Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium webdriver ExtJS组合框具有相同的Xpath、ID和CSS路径,具有动态变化的ID,并且能够使用SeleniumWebDriver选择下拉元素_Selenium Webdriver - Fatal编程技术网

Selenium webdriver ExtJS组合框具有相同的Xpath、ID和CSS路径,具有动态变化的ID,并且能够使用SeleniumWebDriver选择下拉元素

Selenium webdriver ExtJS组合框具有相同的Xpath、ID和CSS路径,具有动态变化的ID,并且能够使用SeleniumWebDriver选择下拉元素,selenium-webdriver,Selenium Webdriver,我一直在测试一个基于extJS的web应用程序,它包含许多下拉组合框。每个框都有相同的类名,每次加载页面时ID都会动态变化 组合框不是典型的下拉框。它包含一个文本框,后跟下拉按钮图像,然后单击该下拉按钮提供下拉框中的所有选项。我想从下拉框中选择一个特定的元素。 使用firepath检查下拉按钮元素时,其html代码为 <div id="ext-gen1103" class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-fo

我一直在测试一个基于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"/> 
<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;"/> 

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

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

  • ****帮助信息****
  • ABC公司
我想从下拉框中选择“帮助NG”或“ABC公司”。但我真的被如何集成以及如何编写SeleniumWebDriver代码从下拉框中选择元素所打动,因为下拉按钮只包含id和类(id不断变化,所有其他下拉按钮的类名都相同)。有没有人跨过这样的场景,请帮助我解决这个问题,因为这会完全占用时间。(

您需要使用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.");

当您发布HTML或代码时,请每行缩进4个空格,并花一分钟时间使用美化工具(如正确设置格式)。这会使阅读更容易,从而使您的问题更容易得到回答。谢谢!您尝试了什么,结果如何?正如您在学校所做的那样……请展示您的作品。:)这是获得问题答案的过程的一部分。它对你很有帮助,因为它迫使你调查自己的问题并仔细思考。它还向读者证明,你做了功课,并做出了合理的尝试来回答自己的问题。第三,它帮助读者找到并诊断问题,从而为您提供更好的答案,减少我们的时间浪费。您还应指定问题和标记中使用的语言。另请参阅此链接,该链接使用的方法略有不同