Eli
Eli

Reputation: 181

WebDriver HtmlUnitDriver NoSuchElementException

I'm using Webdriver to test my web application. When I work with FireFoxDriver or ChromeDriver everything seems to be ok. When I work with HtmlUnitDriver though things start to go wrong.

Here is a sample code:

WebDriver driver = new HtmlUnitDriver();
driver.get("http://localhost:8099/");
WebElement loginButton = driver.findElement(By.xpath("//button[@type='button']"));
loginButton.click();

i'v looked at the driver.getPageSource result, and the source code presented there is very partial.

it doesnt show me all the elements. it is the same a clicking view source on the page. what i need from the driver is the entire source, like firebug or chrome inspector give me.

any ideas on how i can retrieve it?

my app was written with the GWT.

thanks a million

Upvotes: 0

Views: 1542

Answers (2)

chooban
chooban

Reputation: 9256

I believe that the HTMLUnitDriver emulates IE by default (link) and there are other questions related to clicking buttons with IE. Have you tried this?

// Press enter on the button
loginButton.sendKeys("\n"); 

Also, have you tried adding an ID to the element and using that to find the button?

Upvotes: 0

Sergii Pozharov
Sergii Pozharov

Reputation: 17858

Have you tried to enable JavaScript for HtmlUnitDriver?

Upvotes: 1

Related Questions