これらの要素は既に存在するためfindElement()
、それらの要素で使用すると、StaleReferenceException を回避でき、問題ありません。
テスト フローは次のようになります (ここにあるフレームワークを使用していることに注意してください)。
@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..
}
}
そこでフレームワークを使用すると、はるかに簡単になり、独自の待機と ajax のアカウントを処理します。ただし、バニラを好む場合は-
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.
}
これら 2 つの解決策の代わりに、WebDriverWait
's.. を使用することもできます。あなたの場合、次のようになります...
WebDriverWait.until(ExpectedConditions.textPresentIn(By.id("existingId"), "some text you'd expect"));