【发布时间】:2015-05-18 21:36:44
【问题描述】:
我开始使用 WebDriver 和 Java 进行 UI 自动化。当我尝试选择组合框的元素时遇到问题。这是代码:
WebDriver driver = new FirefoxDriver();
driver.get("http://intersite.com/");
new Select(driver.findElement(By.xpath(".//*[@id='term']"))); //Exception happens in this line org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='term']"}
这是网站上的代码(我用Firepath知道Xpath):
<select name="term" onchange="getTipDoc('');" id="term" class="termination"><option value="">-- Select an Option --</option>
<option value="OPT1">Option 1</option>
<option value="OPT2">Option2</option>
</select>
我在标签选择中看到,ID 属性是正确的,但总是发生异常。我尝试使用其他方法来定位像“By.id”这样的元素,但也不起作用。我能做什么?
问候!
【问题讨论】:
标签: java xpath selenium-webdriver