【问题标题】:HtmlUnit driver doesn't execute JavaScriptHtmlUnit 驱动程序不执行 JavaScript
【发布时间】:2013-01-29 00:39:26
【问题描述】:

我是 HtmlUnit 的新手,在登录时遇到了一些问题。 下面的代码对FireFoxDriver 工作得很好,但对HtmlUnitDriver 却失败了。问题是它在点击“登录”链接时没有执行javascript

查看html的网址:https://fleetworks.trimbletl.com/fleet/start.do

HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME_16);
driver.setJavascriptEnabled(true);
WebDriverWait wait = new WebDriverWait(driver, 10);

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 loginButtonElement = driver.findElement(By.linkText("Log in"));
loginButtonElement.click();

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("headerFrame"));

堆栈跟踪:

    13, 2013 2:47:54 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
    WARNING: Obsolete content type encountered: 'text/javascript'.
    13, 2013 2:47:54 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
    WARNING: Obsolete content type encountered: 'text/javascript'.
    13, 2013 2:47:55 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
    WARNING: Obsolete content type encountered: 'text/javascript'.
   2013 2:47:56 PM com.gargoylesoftware.htmlunit.WebClient loadDownloadedResponses
   INFO: No usage of download: com.gargoylesoftware.htmlunit.WebClient$LoadJob@1b55ca5

   Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10  seconds waiting for frame to be available: headerFrame
   Build info: version: '2.29.1', revision: 'dfb1306b85be4934d23c123122e06e602a15e446',  time: '2013-01-22 12:58:05'
   System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:  '1.7.0_11'
    Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:255)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:224)
at com.yukon.qasetup.xmlService.XMLService.main(XMLService.java:77)
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)

【问题讨论】:

  • 日志中的这条消息,可以指向某些东西...警告:遇到过时的内容类型:'text/javascript'。不确定。
  • 我认为警告可以忽略; HtmlUnit 似乎可以应付,即使它不喜欢内容类型。真正的问题是找不到框架 headerFrame 的异常。
  • @user1991529:应该由登录按钮触发的javascript是否存在特定问题?还是网站上的任何 javascript 都失败了?
  • 也许你需要放慢 HTMLUnit 的速度。请记住:HTMLUnit 比 firefox 快得多。这意味着您可能在加载 javascript 之前单击登录按钮。 (Selenium 2 不会等待页面加载)。也许你需要一个 while 构造,只要 headerFrame 不可见,它就会单击登录按钮。
  • 登录后我只能看到“headerFrame”,如果是?请分享测试用户名/密码。也许我可以帮忙...

标签: selenium selenium-webdriver htmlunit


【解决方案1】:

您的类 HtmlUnitDriver 不是标准 Selenium 包的一部分,是吗?据我所知,对于 HtmlUnit,您必须使用 DesiredCapabilities.HtmlUnit() 或 DesiredCapabilities.HtmlUnitWithJavaScript() 创建一个 RemoteWebDriver 实例。

你能看看你的 HtmlUnitDriver 类吗?也许使用了 DesiredCapabilities.HtmlUnit() 而不是 DesiredCapabilities.HtmlUnitWithJavaScript() !?

【讨论】:

    猜你喜欢
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 2014-11-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多