我对HtmlUnit
不熟悉并且遇到"Setup"
时遇到了一些问题
菜单项位于框架中。
下面的代码适用于FireFox驱动程序,而对HtmlUnitDriver 失败,
HtmlUnitDriver driver = new HtmlUnitDriver();
driver.get(fleetWorkURL);
WebElement usernameElement = driver.findElement(By.name("j_username"));
usernameElement.sendKeys(username);
WebElement passwordElement = driver.findElement(By.name("j_password"));
passwordElement.sendKeys(password);
WebElement logInButton = driver.findElement(By.className("button_acunia"));
logInButton.click();
driver.switchTo().frame("headerFrame");
WebElement setupMenuItemElement = driver.findElement(By.id("setup"));
setupMenuItemElement.click();
// Check the title of the page, should be Fleet Works Setup
System.out.println("Page title is: " + driver.getTitle());
driver.close();
使用HtmlUnit驱动程序时错误 -
Exception in thread "main" org.openqa.selenium.NoSuchFrameException: Unable to locate frame with name or ID: headerFrame
Build info: version: '2.28.0', revision: '18309', time: '2012-12-11 15:53:30'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_13'
Driver info: driver.version: unknown
at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitTargetLocator.frame(HtmlUnitDriver.java:908)
at com.yukon.qasetup.xmlService.Example.main(Example.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
帧:
<frameset border="0" rows="0,0,0,0,0,90,*" onunload="leave()" onload="initMainWindow()">
<frame src="/fleet/html/empty.html" name="refreshTerminalsFrame" style="visibility: hidden; width: 0px; height: 0px; border: 0px;">
<frame src="/fleet/html/empty.html" name="refreshDriversFrame" style="visibility: hidden; width: 0px; height: 0px; border: 0px;">
<frame src="/fleet/html/empty.html" name="refreshExternalDevicesFrame" style="visibility: hidden; width: 0px; height: 0px; border: 0px;">
<frame src="/fleet/html/empty.html" name="refreshUsersFrame" style="visibility: hidden; width: 0px; height: 0px; border: 0px;">
<frame src="/fleet/html/empty.html" name="refreshCustomersFrame" style="visibility: hidden; width: 0px; height: 0px; border: 0px;">
<frame src="/fleet/jsp/header/headerFrame.jsp" name="headerFrame" frameborder="0" scrolling="no">
<frame src="/fleet/home.do" name="displayFrame" frameborder="0" scrolling="yes">
</frameset>
答案 0 :(得分:1)
尝试以下方法:
HtmlUnitDriver driver = new HtmlUnitDriver(true); // enable javascript