0

I see many examples of waiting for html controls to become "present" , ie as a result of an ajax call, java event handler, and so on.

But in my case, my ajax code does not instantiate, or make visible, a new control; it repopulates existing controls with new values.

What I want to do is implicitly wait for these values to "show up", but I can't tell if this is possible in Selenium 2.0?

Michael

4

2 に答える 2

0

これらの要素は既に存在するため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"));
于 2013-10-10T13:56:47.197 に答える
0

Seleniumには2種類の待機コマンドがあります

1 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

2 WebDriverWait.until(condition-that-finds-the-element)

例:
Selenium-WebDriver に Java で数秒間待機するように依頼するにはどうすればよいですか? 使用できる可能性があるものを示します

public WebElement fluentWait(final By locator) {
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
        .withTimeout(30, TimeUnit.SECONDS)
        .pollingEvery(5, TimeUnit.SECONDS)
        .ignoring(NoSuchElementException.class);
}

詳細については、 http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/FluentWait.htmlも確認してください。

于 2013-10-10T13:54:55.547 に答える