Selenium Java-下拉选择,其中Style-display为none
当我尝试使用样式显示选择下拉列表时:无 备选案文1:Selenium Java-下拉选择,其中Style-display为none,java,selenium,Java,Selenium,当我尝试使用样式显示选择下拉列表时:无 备选案文1: WebElement sysDropDown = driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddlFeedStatus")); Select sDropdown = new Select(sysDropDown); sDropdown.selectByVisibleText("01 - Quarantined"); 上述代码呈现错误: 元素不可交互:元素当前不可见且可能不可
WebElement sysDropDown = driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddlFeedStatus"));
Select sDropdown = new Select(sysDropDown);
sDropdown.selectByVisibleText("01 - Quarantined");
上述代码呈现错误:
元素不可交互:元素当前不可见且可能不可用
被操纵
备选案文2:
WebElement hiddenWebElement =driver.findElement(By.xpath("//select[@name='ctl00$ContentPlaceHolder1$ddlFeedStatus']"));
((JavascriptExecutor)driver).executeScript("arguments[0].click()",hiddenWebElement);
选项2识别下拉列表,但无法从下拉列表中选择项目
任何帮助都将不胜感激
尝试了我在网站上看到的几个选项,但没有多大帮助您可以尝试使用Javascript更改
样式
属性,例如:
hiddenWebElement = driver.findElement(
By.xpath("//select[@name='ctl00$ContentPlaceHolder1$ddlFeedStatus']"));
((JavascriptExecutor)driver).executeScript(
"arguments[0].style.display = 'block';", hiddenWebElement);
之后,您可以尝试Javascript单击或常规单击。您可以右键单击->检查并查看它是否真的是一个下拉列表吗?如果下拉列表可见,但仍然出现此错误,则可能不是html下拉列表。它可能看起来像一个,但只有在您检查或查看代码时才能确认 如果元素是html下拉列表,请使用以下代码查看它是否有效:
WebElement sysDropDown = driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddlFeedStatus"));
Coordinates coordinate = ((Locatable) sysDropDown).getCoordinates();
coordinate.onPage();
coordinate.inViewPort();
Select sDropdown = new Select(sysDropDown);
sDropdown.selectByVisibleText("01 - Quarantined");
我认为你是对的…看起来不像html下拉列表…它在下拉列表中内置了搜索功能如果你解决了Locatable(缺少depdency),你仍然可以尝试它。或者,您可以提供文本来搜索输入,然后选择下拉列表。