extjs - 如何在 selenium webdriver 中处理 ExtJS 的组合框

标签 extjs selenium-webdriver

嗨,我有一个基于 ExtJS 的 UI。我已经知道在 ExtJS 中组合框不是真正的组合框,而是输入文本字段、下拉框图像和列表的组合。现在我能够识别控件,但我坚持从列表中选择值。在 HTML 源代码中,我看到列表显示为一个单独的 div,并在我们单击下拉列表时附加在源代码的末尾。在下拉控件的 HTML 源代码下方找到。
{

<div id="ext-gen678" class="x-form-field-wrap x-form-btn-plugin-wrap" style="width: 556px;">
<div id="ext-gen676" class="x-form-field-wrap x-form-field-trigger-wrap x-trigger-wrap-focus" style="width: 521px;">
<input id="ext-gen677" type="hidden" name="GHVOg:#concat#~inputFld~ISGP_UNIV:ft_t_isgp.prnt_iss_grp_oid:0" value="">
<input id="GHVOg:Mixh8:0" class="x-form-text x-form-field gs_dropDown_input gs_req x-form-invalid x-form-focus" type="text" autocomplete="off" size="24" style="width: 504px;">
<img id="trigger-GHVOg:Mixh8:0" class="x-form-trigger x-form-arrow-trigger" alt="" src="../../ext/resources/images/default/s.gif">

}

在下拉列表的 HTML 源代码下方找到:
<div id="ext-gen726" class="x-layer x-combo-list x-resizable-pinned" style="position: absolute; z-index: 12007; visibility: visible; left: 294px; top: 370px; width: 554px; height: 123px; font-size: 11px;">
<div id="ext-gen727" class="x-combo-list-inner" style="width: 554px; margin-bottom: 8px; height: 114px;">
<div class="x-combo-list-item"></div>
<div class="x-combo-list-item">12h Universe</div>
<div class="x-combo-list-item">1h Universe</div>
<div class="x-combo-list-item">24h Universe</div>
<div class="x-combo-list-item">2h Universe</div>
<div class="x-combo-list-item x-combo-selected">4h Universe</div>

现在我在从列表中选择值时遇到问题,因为列表的 div 元素没有附加到控件上。
另请参阅屏幕截图,其中我有多个类似的控件 [命名为“向 Universe 添加安全性”]
Screenshot of the ExtJS UI

在屏幕截图中,您可以看到多个下拉菜单 [Add security to Universe] 突出显示,并且所有下拉菜单都具有相同的值出现在列表中。那么我如何从下拉列表中识别这些值。
我想知道 ExtJS 如何维护下拉 div 元素与组合框小部件的映射,以便我可以使用相同的逻辑来识别列表。谁能告诉我如何在 selenium webdriver 中做这件事?

最佳答案

您是否注意到只有一个可见 x-combo-list在页面上? (让我知道您是否可以同时打开两个组合列表)

所以你只需要关心可见的x-combo-list .

CSS 选择器:.x-combo-list[style*='visibility: visible;'] .x-combo-list-item
Xpath://*[contains(@class, 'x-combo-list') and contains(@style, 'visibility: visible;')]//*[contains(@class, 'x-combo-list-item')]

// untested java code, just for the logic
public void clickComboItem(WebElement input, String target) {
    input.click(); // click input to pop up the combo list
    List<WebElement> comboItems = driver.findElements(By.cssSelector(".x-combo-list[style*='visibility: visible;'] .x-combo-list-item"));
    for (int i = 0; i <= comboItems.size(); i++) {
        WebElement item = comboItems.get(i);
        if (item.getText().eqauls(target)) {
            item.click();
            break;
        }
    }
}

// compilable C# version
public void ClickComboItem(IWebElement input, string target) {
    input.Click();
    IList<IWebElement> comboItems = driver.findElements(By.CssSelector(".x-combo-list[style*='visibility: visible;'] .x-combo-list-item"));
    comboItems.First(item => item.Text.Trim() == target).Click();
}

关于extjs - 如何在 selenium webdriver 中处理 ExtJS 的组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16296490/

相关文章:

sencha-touch - 如何获取 FieldSet 的元素

python - 使用 selenium webdriver 在 firefox 中打开 www.google.com 而不是 www.google.co.in

java - 如何使用 selenium webdriver 计算网页上可用的图像数量?

gridview - 如何将复选框列添加到 Extjs 网格

extjs - 在 cq5 对话框的提交事件之前使用

javascript - Ext JS 4.1.3 : Returning values with Ext. Ajax.request

javascript - 使用 Webdriver.IO 按类选择元素

javascript - Internet Explorer 8 的 extjs 问题

java - 上传图片 - 元素当前不可见

java - 如何在不同的PC上运行jar文件(具有selenium自动化、webdriver)