私は、この質問に既に回答していたことをもう少し前に尋ねられましたが、私は自分の期待する条件を書くための具体的な例を提供すると思いました。この予想条件クラスを作成することにより:
wait.until(new ProxyWebElementLocated(authorField));
をそして、それはあなたが本当に必要とするすべてです:
/**
* Since the proxy won't try getting the actual web element until you
* call a method on it, and since it is highly unlikely (if not impossible)
* to get a web element that doesn't have a tag name, this simply will take
* in a proxy web element and call the getTagName method on it. If it throws
* a NoSuchElementException then return null (signaling that it hasn't been
* found yet). Otherwise, return the proxy web element.
*/
public class ProxyWebElementLocated implements ExpectedCondition<WebElement> {
private WebElement proxy;
public ProxyWebElementLocated(WebElement proxy) {
this.proxy = proxy;
}
@Override
public WebElement apply(WebDriver d) {
try {
proxy.getTagName();
} catch (NoSuchElementException e) {
return null;
}
return proxy;
}
}
はその後、これはあなたがすることができます。
public final class MyExpectedConditions {
private MyExpectedConditions() {}
public static ExpectedCondition<WebElement> proxyWebElementLocated(WebElement proxy) {
return new ProxyWebElementLocated(proxy);
}
}
、あなたはこのような何かを行うことができるようになる:
wait.until(MyExpectedConditions.proxyWebElementLocated(authorField));
MyExpectedConditions
クラスがすることができますが、さらに一歩抽象化をしたい場合しかし、あなたはこのようなクラスを作成することができます1つの予想された条件に対して少し過剰ですが、複数の期待条件がある場合は、それを使うとより良いものになります。
ExpectedConditions
クラスのメソッドをラップするMyExpectedConditions
クラスにメソッドを追加すると、1つの場所からすべての予想条件を取得できます。 (私は、ラッパーメソッドを実行する代わりにExpectedConditions
を拡張することを提案しますが、拡張することは不可能なプライベートコンストラクターを持っていますので、ラッパーメソッドを1つの場所にすべてが欲しいもののための唯一のオプションとして残しています)。
ありがとう、私は自分の条件と作業を作成しました! – Arthur