【发布时间】:2012-04-21 13:51:11
【问题描述】:
我需要点击以下xPath指向的链接:html/body/div[2]/ul/li[9]/a(使用firepath生成)相应的Html片段如下: 注销
我的代码是这样的:
HtmlUnitDriver driver= new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
WebElement logoffElement = (new WebDriverWait(driver, 10))
.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.xpath("html/body/div[2]/ul/li[9]/a"));
}});
logoffElement.click();
以上代码适用于 Firefoxdriver,但不适用于 HtmlUnitdriver。 HtmlUnitdriver 给出以下错误:
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate a node using html/body/div[2]/ul/li[9]/a
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_23'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByXPath(HtmlUnitDriver.java:802)
at org.openqa.selenium.By$ByXPath.findElement(By.java:344)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1244)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:984)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1241)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:396)
at com.nike.automation.Task$1.apply(Task.java:70)
at com.nike.automation.Task$1.apply(Task.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:201)
【问题讨论】:
-
启用javascript因此解决了我的问题。但是面对新的“FailingHttpStatusCodeException - Too much redirect for ..”,捕捉状态码 302 的错误很重要,这有意义吗?再次,FirefoxDriver 没有这样的问题,但 HtmlUnit 面临它。我感到迷茫...请帮助..
标签: webdriver htmlunit selenium-firefoxdriver