我有一个使用ExtJS呈现的网页。它使用一些生成的ID呈现多个Comboboxes。每个组合框都有不同的选项。我怎样才能找出每个组合中选择哪个值?如何通过硒获取ExtJS组合框的选定值?
在调试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>
呈现在“样本” 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
,因为有n o渲染组合的div与保存可用选项的div之间的映射。如果它只是一个组合,那么它会很好,但在我的情况下,我有多个具有相同值的组合框。
html的样本将会有帮助。谢谢。 – 2014-08-27 11:24:32
代码和生成的HTML添加 – sidgate 2014-08-27 12:56:42
您是否尝试过使用'cls'选项在每个组合框中添加一个类并在Selenium中使用'XPath'查询它们? – Ben 2014-09-02 04:14:45