gpt4 book ai didi

javascript - 如何通过selenium获取ExtJS combobox的选中值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:54 28 4
gpt4 key购买 nike

我正在使用 ExtJS 呈现网页。它使用一些生成的 ID 呈现多个组合框。每个组合框都选择了不同的选项。如何找出每个组合中选择的值?

在调试 HTML DOM 时,我观察到 ExtJS 渲染 DIV 是不同的,并且最后可选择的选项在不同的 DIV 中渲染。所以我无法定义任何 XPath 来找出选定的值。

以下是代码片段

<div class="guide-bg" id="sample"><table>
<tr><td id="row1"> </td></tr>
<tr><td id="row2"></td></tr>
</table></div>

<script>
Ext.namespace('Ext.exampledata');
Ext.exampledata.states = [['Alabama'],[ 'Alaska'],['Arizona']];

var store1 = new Ext.data.SimpleStore({
fields: [ 'state'],
data : Ext.exampledata.states
});

var combo1 = new Ext.form.ComboBox({
store: store1, displayField:'state', typeAhead: true,
mode: 'local', forceSelection: true, triggerAction: 'all',
emptyText:'Select...', selectOnFocus:true, renderTo: 'row1'
});

var combo2 = new Ext.form.ComboBox({
store: store1, displayField:'state', typeAhead: true,
mode: 'local', forceSelection: true, triggerAction: 'all',
emptyText:'Select...', selectOnFocus:true, renderTo: 'row2'
});
</script>

渲染后在“sample”div 生成的 HTML 是

<div class="guide-bg" id="sample">
<table>
<tbody><tr><td id="row1">
<div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen148" style="width: 206px;">
<input type="text" name="ext-comp-1028" id="ext-comp-1028" autocomplete="off" size="24" class="x-form-text x-form-field x-form-empty-field" style="width: 181px;">
<img class="x-form-trigger x-form-arrow-trigger" src="sp.gif" id="ext-gen149">
</div></td></tr>
<tr><td id="row2">
<div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen150" style="width: 206px;">
<input type="text" name="ext-comp-1029" id="ext-comp-1029" autocomplete="off" size="24" class="x-form-text x-form-field x-form-empty-field" style="width: 181px;">
<img class="x-form-trigger x-form-arrow-trigger" src="sp.gif" id="ext-gen151">
</div></td></tr>
</tbody></table>
</div>

选项像这样独立出现在 DOM 的末尾

<div class="x-layer x-combo-list " id="ext-gen146" style="position: absolute; z-index: 12005; visibility: hidden; 
left: -10000px; top: -10000px; width: 204px; height: 129px; font-size: 12px;">
<div class="x-combo-list-inner" id="ext-gen147" style="width: 204px; height: 129px;">
<div class="x-combo-list-item x-combo-selected">Alabama</div>
<div class="x-combo-list-item">Alaska</div>
<div class="x-combo-list-item">Arizona</div>
</div>
</div>

我不能只遍历每个 x-combo-list-inner,因为呈现组合的 div 和包含可用选项的 div 之间没有映射。如果它只是一个组合,那就没问题了,但在我的例子中,我有多个具有相同值的组合框。

最佳答案

使用 Selenium 执行 JS(How to use JavaScript with Selenium WebDriver Java)。在 js 中,您可以使用“Ext.ComponentQuery.query('combo')[0].value”代码来获取组合值

关于javascript - 如何通过selenium获取ExtJS combobox的选中值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25525323/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com