HtmlUnit driver doesn't execute JavaScript
Asked Answered
A

1

6

I am new to HtmlUnit and am having some trouble with logging in. Below code works perfectly fine for FireFoxDriver but fails for HtmlUnitDriver. The problem is it not executing javascript while clicking on "Login" link;

site url for html viewing: 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"));

StackTrace:

    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)
Aircool answered 13/2, 2013 at 12:52 Comment(6)
this message in the log, can point to something ... WARNING: Obsolete content type encountered: 'text/javascript'. not sure.Argal
I think the warnings can be ignored; HtmlUnit seems to cope, even if it doesn't like the content type. The real issue is the exception where it can't find the frame headerFrame.Nationalist
@user1991529: Is it a specific problem with the javascript which is supposed to be fired by the login button? Or does it fail for any javascript on the site?Nationalist
Maybe you need to slow down HTMLUnit. Remember: HTMLUnit is way faster than firefox. That means maybe you click the login-button before the javascript is even loaded. (Selenium 2 doesn't wait for the page to load). Maybe you will need an while-constuct, that clicks the login-button as long as the headerFrame isn't visible.Loci
I can only see "headerFrame" once I am logged in, if Yes? please share test username/password. May be I can help...Coughlin
Can you add what version of Selenium you are using and what version of the browser you have on your local system?Transfer
Q
-1

Your class HtmlUnitDriver is not part of the standard Selenium package, is it? As far as i know, for HtmlUnit you have to create a RemoteWebDriver instance with either DesiredCapabilities.HtmlUnit() or DesiredCapabilities.HtmlUnitWithJavaScript().

Can you loook inside your HtmlUnitDriver class? Maybe DesiredCapabilities.HtmlUnit() instead of DesiredCapabilities.HtmlUnitWithJavaScript() is used!?

Quade answered 12/1, 2016 at 10:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.