Since those elements already exist, if you use findElement()
on those elements, then you'll avoid StaleReferenceException's, and you'll be fine.
Your test flow would look something like this (mind you this is using the framework found here
@Config(url="http://systemunder.test", browser=Browsers.CHROME)
public class MyTest extends AutomationTest {
@Test
public void myTest() {
click(By.id("somethingThatTriggersAjax")
.validateText(By.id("existingId"), "test"); // this would work..
}
}
Using the framework there, it's much easier, and handles it's own waits, as well as accounts for ajax. however if you prefer vanilla -
public void test() {
WebElement element;
element = driver.findElement(By.id("somthingThatTriggersAjax"));
// now ajax has done something.
element = driver.findElement(By.id("existingId")); // now this will be updated with the new element information.
}
An alternative to these two solutions, would be to use WebDriverWait
's.. In your case, it'd be something like...
WebDriverWait.until(ExpectedConditions.textPresentIn(By.id("existingId"), "some text you'd expect"));