我正在尝试从此页面的“离开”列表框中选择一个选项 Pune(PNQ) http://book.spicejet.com/
driver.get("http://book.spicejet.com");
Thread.sleep(50000);
Select S = new Select(driver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1")));
S.selectByValue("PNQ");
但我收到此错误:
org.openqa.selenium.ElementNotVisibleException
我是 Selenium 新手。请帮忙。
最佳答案
直接来自 Selenium 源 -
/**
* Thrown to indicate that although an element is present on the DOM, it is not visible, and so is
* not able to be interacted with.
*/
public class ElementNotVisibleException...
正如它所说,该元素位于 DOM 上,但不可见且无法操作。如果在该元素存在之前您必须采取先发制人的操作,那么就执行该操作。
Google 图像搜索就是一个例子。当您单击图像时,会出现一个带有图片的黑框。该元素始终存在,但您必须 click
在图像上使其显示。
听起来您的选择框也发生了同样的事情。
编辑
我冒昧地进一步研究了您的特定问题..看起来该网站隐藏了 <select>
标签,因为它由一些 jQuery 内容填充。
不要使用选择标签并按值选择,而是这样做,
driver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1_CTXT").sendKeys("PNQ");
driver.findElement(By.cssSelector("a[value='PNQ']").click();
希望这有帮助。
关于java - Selenium Webdriver - 无法从列表框中选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19012576/