2

テストスクリプトのすべてのWeb要素の前に明示的な待機を追加しようとしています

私のコードは

import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
                     .
                     .
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(presenceOfElementLocated(By.id("name")));

driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys("Create_title_01");

私が見るエラーは次のとおりです。

    java.lang.NullPointerException
at org.openqa.selenium.support.ui.FluentWait$1.apply(FluentWait.java:176)
at org.openqa.selenium.support.ui.FluentWait$1.apply(FluentWait.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:174)

ありがとう

4

3 に答える 3

5

presentOfElementLocatedおよびその他のAjaxConditionメソッドを使用する場合

あなたが使用する必要があります

org.openqa.selenium.support.ui.ExpectedConditions

クラス。コードは次のようになります。

wait.until(ExpectedConditions.presenceOfElementLocated(By.id("name")));
于 2012-05-07T15:07:20.370 に答える
0

AJAX呼び出しのイベントに応じて、waitForElementPresentまたはwaitForElementNotPresentを使用することをお勧めします。

ただし、それでもwait.untを使用したい場合は、これが私のやり方です(そしてそれが機能します)

wait = new WebDriverWait(wedriver1, TimeSpan.FromSeconds(5));
.....
button.Click();
wait.Until(webdriver1 => webdriver2.webelement.GetAttribute("style").Contains("display: block"));

untilメソッドが取る条件での属性変更の例を示しました。あなたは次のようなことをすることができます。

driver.findElement(By.id( "name"))。displayed(wait.until内の条件に対して。

于 2012-05-07T00:19:34.187 に答える
0

WebDriverWait wait初期化後に次の行が必要なようです。

wait.ignoring(NoSuchElementException.class);
于 2014-01-22T14:08:24.620 に答える