Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDriver HTMLUnit issues with Ajax

I want to test a site using selenium webdriver (java), but that site contains ajax and HTMLUnit does not see the ajax content.

Is there a workaround?

Example:

WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
//login into your account
this.login(driver);
//click on edit Profile Link into an ajax-loaded tab
driver.findElement(By.id("editProfile")).click();
//Result: org.openqa.selenium.NoSuchElementException 
like image 423
Krzys Avatar asked Apr 11 '12 08:04

Krzys


1 Answers

use Wait condition before interaction with element with must appear after ajax response.

WebDriverWait wait = new WebDriverWait(webDriver, 5);
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_to_element")));

this makes webDriver to wait for your element during 5 secs. This question was asked earlier.

like image 104
Pazonec Avatar answered Sep 26 '22 15:09

Pazonec