首页 文章

ExtJS组合框具有相同的Xpath,ID,具有动态更改IDS的CSS路径,并且能够使用Selenium webDriver选择下拉元素

提问于
浏览
0

我真的很难测试一个包含许多下拉组合框的extJS基于web的应用程序 . 并且每个框具有相同的类名,并且每次加载页面时ID都会动态更改 .

组合框不是典型的下拉框 . 它包含一个文本框,然后是下拉按钮图像,然后单击该下拉按钮,提供下拉框中的所有选项 . 我想从下拉框中选择一个特定的元素 . 当使用firepath检查下拉按钮元素时,它的html代码是

<div id="ext-gen1103" class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-first" role="button"/>

类似地,如果我输入下拉文本框(其id仅为常量且不会更改),则html代码为

<input id="NSClientCombo-inputEl" class="x-form-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" type="text" placeholder="Select One" name="NSClientCombo" autocomplete="off" aria-invalid="false" data-errorqtip="" style="width: 100%; height: 28px;"/>

如果我检查任何下拉元素的html代码是

<div id="boundlist-1048-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: 187px;">
   <ul class="x-list-plain">
      <li class="x-boundlist-item" unselectable="on" role="option">****HELP NG****</li>
      <li class="x-boundlist-item" unselectable="on" role="option">ABC Inc.</li>

我想从下拉框中选择“HELP NG”或“”ABC Inc“” . 但我真的很感兴趣如何集成和如何编写selenium webdriver代码从下拉框中选择一个元素,因为下拉按钮只包含id和class(id不断更改,所有其他下拉按钮的类名相同) . 有没有人越过这样的场景,请帮助我解决这个问题,因为这是完全消磨时间 . :(

1 回答

  • 0

    您需要使用Ext.getCmp()函数来检索此组合的webElement . 请参阅下面的代码 .

    此代码将返回web元素

    public static IWebElement ExtJsGetWebElementById(this IWebDriver driver, string id)
            {
    
                IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    
                var script = "return Ext.getCmp('" + id + "').el.dom";
                var Element = js.ExecuteScript(script) as IWebElement;
                return Element;
    
            }
    

    下一个函数将用于打开组合框并使用键盘快捷键为其设置特定值 .

    public static void ExtJsSetComboValueWithKeyBoard(this IWebDriver driver, string comboId, string valueToSet)
            {
    
                var element = driver.ExtJsGetWebElementById(comboId);
                element.SendKeys(Keys.Down);
                Thread.Sleep(3000);         
    
                element.SendKeys(valueToSet);
                Thread.Sleep(3000);
    
                element.SendKeys(Keys.Enter);
                Thread.Sleep(3000);
    
            }
    

    要使用上述方法,请在测试用例中使用它 .

    _webDriver.ExtJsSetComboValueWithKeyBoard("NSClientCombo","ABC Inc.");
    

相关问题