Reputation: 23790
Here is a sample code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class PrimeFaces {
public static void main(String[] args) throws Exception {
HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(true);
WebDriverWait wait = new WebDriverWait(htmlUnitDriver,10);
htmlUnitDriver.get("http://primefaces-rocks.appspot.com/ui/datatableComplex.jsf");
htmlUnitDriver.findElementById("j_idt44:j_idt45_row_0").click();
WebElement until = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ui-dialog-title-j_idt44:j_idt59")));
}
}
Here, id: j_idt44:j_idt45_row_0 is for the first row found in this page: http://primefaces-rocks.appspot.com/ui/datatableComplex.jsf
When you click on this row, you will see a window popping up containing an element with id: j_idt44:j_idt59
But with HtmlUnitDriver this element is not visible becuase I think either HtmlUnitDriver is not clicking on the row, or the event listener is not being triggered.
How can I solve this problem?
Upvotes: 3
Views: 1512
Reputation: 1291
Your id contains a special character : :
You have to escape it if you want to access to your div:
htmlUnitDriver.findElementByCssSelector("#j_idt44\\:j_idt45_row_0").click();
Hope that helps.
Upvotes: 1
Reputation: 10329
Seems like a timing problem. I used the following code:
driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.get("http://primefaces-rocks.appspot.com/ui/datatableComplex.jsf");
driver.findElement(By.id("j_idt44:j_idt45_row_0")).click();
assert driver.findElement(By.id("j_idt44:j_idt59")).isDisplayed();
works perfectly fine for me.
Note that with a 10 second timeout, it fails for me every time.
Upvotes: 2
Reputation: 925
I think You should go with similar approach that click on button and wait for execution, but first make sure that you are finding right element.
response_object = htmlUnitDriver.findElementById("j_idt44:j_idt45_row_0").click();
//test your condition here, and retries until you get the results
synchronized (respnse_object) {
page.wait(2000); //wait
}
Upvotes: -1