質問

Selenium RCを搭載したC#でSeleniumを使用していくつかの自動化された相互作用テストを行っていますが、障害に遭遇しました。

このHTMLを指定:

<select id="my-select-list">
    <option value="1">First option</option>
    <option value="2">Second option</option>
    <option value="3">Third option</option>
    <option value="4">Fourth option</option>
</select>

オプション&quot; Third Option&quot;を確認するためにテストしたいページに存在します。

次のテストはすべて失敗しました。つまり、falseを返します。

Selenium.IsElementPresent("//select/option[@label='Third option']")
Selenium.IsElementPresent("//select[option='Third option']")
Selenium.IsElementPresent("//select[contains(option, 'Third option')]")
Selenium.IsElementPresent("//option[contains(., 'Third option')]")
Selenium.IsElementPresent("//option[contains(text(), 'Third option')]")

それはSelenium(RC / .NET)の制限ですか、それとも別の選択方法がありますか?

オプションの値を使用してテストできることはわかっていますが、変更される可能性があり、テキストは間違いなく変更されません。

編集:PEBKACエラー

申し訳ありませんが、私の悪い。セレンは、私がそれがロードしていると思ったものとは異なるサイトをロードしていたようです。

次のXPathクエリはすべて機能します:

Selenium.IsElementPresent("//option[text()='Third option']")
Selenium.IsElementPresent("//select[option='Third option']")
Selenium.IsElementPresent("//option[contains(., 'Third option')]")
Selenium.IsElementPresent("//option[contains(text(), 'Third option')]")
役に立ちましたか?

解決

私のXPathは少しさびていますが、試しましたか...

Selenium.IsElementPresent("//option[text()='Third option']");

他のヒント

ステップ1:ドロップダウンのすべてのオプションを取得する

Select select = new Select(driver.findElement(By.id(&quot; my-select-list&quot;))); 文字列[] options = select.getOptions();

ステップ2:天気の確認特定のオプション(&quot;第3オプション&quot;)がドロップダウンに存在します。

for(String option:options)

{

if(!option.equals(&quot;第3オプション&quot;))

FAIL;

else

PASS;

}

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top