実際に@FindByは、Page Objects パターンで使用されている要素を取得したいと考えています。
私は2つのクラスを持っています.1つ目は名前が付けられたページオブジェクトTestPageで、2つ目は名前が付けられPageSaveTestています(テストが行われ、TestPage.
@FindByまた、 withxpathとを使用しようとしましたid。
>>これは私のテストページです
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class TestPage {
// get autocomplete input
@FindBy(css = "input[id*='supplierOps_input']")
private WebElement autocompleteSupplierOps;
// getter
public WebElement getAutocompleteSupplierOps() {
return autocompleteSupplierOps;
}
}
>> これは私の PageSaveTest です
// How i "inject" my TestPage
@Page
TestPage testpage;
[...]
// My test
WebElement autocomplete = testpage.getAutocompleteSupplierOps();
String keys = "OP";
autocomplete.sendKeys(keys); // >>>>>>> Error throwed here !
List<WebElement> listSugg = testpage.getSuggestionsSupplierOps();
エラーメッセージ :
org.openqa.selenium.NoSuchElementException : Returned node was not an HTML element.
私の考え :
問題は から来ると思います@FindBy。しかし、この例を使用して、TestPage とテスト、およびこれもビルドします。
質問:誰かがどのように@FindBy機能し、私の例で使用されているかを説明できますか? グラフェンに関するドキュメントは本当に貧弱です。
編集 :
TestPage (上記) でゲッターを変更しました。次のような id 属性値の単純な出力を試みました。
public WebElement getAutocompleteSupplierOps() {
System.out.println(">>>> "+autocompleteSupplierOps.getAttribute("id"));
return autocompleteSupplierOps;
}
しかし、それでも同じエラーが発生@FindByします。
この号に追加する別の @FindBy 仕様。
アップデート :
セレクターを修正しましたが、実際には次のようなドライバー セッションに問題があります。
page2.getAutocompleteSupplierOps();
PAGE 1 ----------------------------------> PAGE 2
driver id:1 ----------------------------------> driver id:2
driver.showPageSource() is empty
return no element found <---------------------- driver.findElement() -> not found
私は3つの異なる方法、 、@FindBy、@Drone WebDriverそして最後@Lukas Frycに私に提案したものを使用しました。