異なるメトリックシステムを持つウェブサイトを自動化しようとしています。 このアプリケーションは、アメリカのメトリックシステム&英国のメトリックシステムの両方をサポートしています。 例:アメリカのサーバーからアプリケーションを開く場合、別のサーバーから同じアプリケーションを開くと、フィート&インチのテキストボックス、&が表示されます。テキストボックスはセンチメートルで表示されます。足&インチとtextbox要素は、それがその後存在だ場合、それは、&が足&インチが存在しない他の場合、これらのテキストボックスに値を入力先に行き、存在していること最初かどうかをチェックするように、私は自分のコードを書いた要素を見つけることができません - セレンのwebdriverを使用して異なるロケールでウェブサイトを自動化
Centimetersのテキストボックスに値を入力します。
/*
*
* This block is for the values in US version
*
*/
@FindBy(xpath = ".//*[@id='profile_height_large_value']")
WebElement CurrentHeightinFeet;
@FindBy(xpath = ".//*[@id='profile_height_small_value']")
WebElement CurrentHeightinInches;
/*
* This block is for the values in British version
*
*/
@FindBy(xpath = ".//*[@id='profile_height_display_value']")
WebElement CurrentHeightinCM;
私のコードはどちらのバージョンにあるかを確認するために以下の通りです。
public void userFitnessDetails() {
CurrentWeight.sendKeys("70");
if (CurrentHeightinFeet.isDisplayed()) {
CurrentHeightinFeet.clear();
CurrentHeightinFeet.sendKeys("5");
CurrentHeightinInches.clear();
CurrentHeightinInches.sendKeys("10");
}
CurrentHeightinCM.clear();
CurrentHeightinCM.sendKeys("170");
}
私は上記のコードを実行すると、私はエラーを取得する - に失敗しました:申し込み org.openqa.selenium.NoSuchElementException:要素を見つけることができません:
{"method":"xpath","selector":".//*[@id='profile_height_large_value']"}
誰かがこれを修正するために私を導いでしたが?
おかげ
私はあなたの提案に従ってコードを変更しましたが、私は自分の状態チェックに問題があります。 – AdiBoy
@FindBy(xpath = ".//*[id='profile_height_display_value ']")) \t WebElement CurrentHeightinCM; \t @FindAll(@FindBy(id = "profile_goal_weight_display_value")) \t WebElement GoalWeight;また、私の状態チェックで私はif(CurrentHeightinFeet.size()> 0 && CurrentHeightinInches.size()> 0){ \t \t \t CurrentHeightinFeet.clear();を使用しています。 \t \t \t CurrentHeightinFeet.sendKeys( "5"); \t \t \t CurrentHeightinInches.clear(); \t \t \t CurrentHeightinInches.sendKeys( "10"); \t \t} "リスト" –
AdiBoy
の場合、メソッドsendKeys(String)は定義されていません。WebElementsを含むリストでsendKeysを呼び出すことはできません。したがって、リストのサイズが0より大きい場合、条件が満たされます。探している要素をリストから抽出する必要があります。 WebElementを取得するには、リストのget(0)メソッドを使用します。次に、sendKeysメソッドを使用します。 – Grasshopper