Selenium Webdriver Java-自动执行Dojo下拉菜单-没有此类元素异常

问题描述

在我的应用程序中单击一个链接后。出现Dojo弹出窗口,如下所述: 我需要从下拉菜单中选择QA / SIT环境值。

JSR223 PreProcessor

有关此的HTML代码如下:

<input class="dijitReset dijitInputInner" type="text" autocomplete="off" data-dojo-attach-point="textBox,focusNode" role="textBox" tabindex="0" id="dijit_form_FilteringSelect_0" aria-required="true" value="" aria-invalid="false">

现在,我尝试使用以下代码从下拉列表中选择值,但没有得到此类元素异常。

Select drpCountry = new Select(driver.findElement(By.xpath("//*[@id=\\\"dijit_form_FilteringSelect_0\\")));
        drpCountry.selectByIndex(4);

我将获得以下内容,没有此类元素异常错误。 任何人都可以在这里解释我所缺少的。如何自动执行Dojo选择下拉列表

解决方法

您可以尝试下面的代码来选择您的选项。首先点击那里的下拉箭头

enter image description here

String option = "QA/SIT"
driver.findElement(By.xpath("//input[@class='dijitReset dijitInputField dijitArrowButtonInner']")).sendKeys(option ) # Choose a valid xpath if its not correct
optionXpath = "//div[text()='"+option+"']"
optEle = driver.findElement(By.xpath(optionXpath ))
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(""arguments[0].click();",optEle );