Note that there are some explanatory texts on larger screens.

plurals
  1. POWebDriver/Selenium 2 doesn't find tag text properly in primefaces component
    text
    copied!<p>I've written a test using webdrive like this: </p> <pre><code>//put stuff in the database fillDatabaseWithParticipants(); WebDriver driver = new FirefoxDriver(); doLogin(driver); //finds the search button and clicks it WebElement searchButton = driver.findElement(By.xpath("/html/body/div/div[8]/div[2]/form/table/tbody/tr[5]/td/button")); searchButton.click(); //clicks the first column of a Primefaces dataTable component to order the content in ascending order driver.findElement(By.xpath(("/html/body/div/div[8]/div[2]/form/div/div/table/thead/tr/th"))).click(); //gets the first table division of the first table row WebElement firstTableDivision = driver.findElement(By.xpath("/html/body/div/div[8]/div[2]/form/div/div/table/tbody/tr/td")); Assert.assertEquals("Should be the same name", "A name inserted by me in the database", firstTableDivision.getText()); </code></pre> <p>What the test does is it opens a Firefox browser, goes to the site and logs in. Then it clicks on the search button of the page and waits for the datatable to appear. When the datatable appears with the results, the test clicks on the first column to order it in ascending order. Then it does the <code>assertEquals()</code> to see if the first name is indeed the first name (one that I inserted in the database in the beginning of the test).</p> <p>The problem I have is that this test only works if I run it on debug mode. If I run it with the Run As... jUnit test in Eclipse the return of <code>firstTableDivision.getText()</code> is the first content the table division had when it was first rendered.</p> <p>I tried using an <code>ExpectedCondition</code> like so:</p> <pre><code>ExpectedCondition e = new ExpectedCondition&lt;Boolean&gt;() { public Boolean apply(WebDriver d) { WebElement changingElement = d.findElement(By.xpath("/html/body/div/div[8]/div[2]/form/div/div/table/tbody/tr/td")); System.out.println(changingElement.getText()); if(changingElement.getText().equalsIgnoreCase("A Name inserted by me")){ return true; } else { return false; } } }; org.openqa.selenium.support.ui.Wait&lt;WebDriver&gt; w = new WebDriverWait(driver, 15); w.until(e); </code></pre> <p>and also tried <code>driver.manage().timeouts().implicitlyWait(new Long(15), TimeUnit.SECONDS);</code>.</p> <p>The expected condition I wrote up there is awful, I know, but it was only to see if it would work. The result with this 2 methods was the same. The returned value is the first name the dataTable had when it was first rendered.</p> <p>I searched for this kind of problem and discovered that it probably is a race condition between the FirefoxDriver and the DOM in the browser.</p> <p>I was wondering if the primefaces had any sort of event I could listen to put it in the <code>ExpectedCondition</code> to end the race condition but wasn't able to find anything like that.</p> <p>What do you guys think I should do? I'm I missing any solution for this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload