繁体   English   中英

无法选择下拉选项

[英]Can't select the drop-down option

使用选择方法,我无法选择下拉菜单

我尝试使用普通和findelement方法以及索引选择方法

这是在其他文件中使用输入值

click(driver,"id",prop.getProperty("state"));
click(driver,"xpath",prop.getProperty("voption"));

和索引选择方法以及

Select drpCountry = new Select(driver.findElement(By.name("country")));
drpCountry.selectByVisibleText("ANTARCTICA");

预期结果:需要单击下拉列表

实际结果: “过时的元素引用:元素未附加到页面文档中”,它显示了这样的错误消息

尝试先找到WebElement ,然后按可见文本进行选择。

WebElement dropDown = driver.findElement(By.id("state"));
new Select(dropDown).selectByVisibleText("ANTARCTICA");

如果这不起作用,但是您没有获得 StaleElementReferenceException请将选择选项更改为selectByIndex()selectByValue()

如果使StaleElementReferenceException指向与driver.findElement(...)则意味着页面上的某些内容已更改,因此应引入某种等待机制。 在这种情况下,我建议使用FluentWait找到dropDown

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM