1

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>

オプション「Third Option」がページに存在することを確認するためにテストしたいと思います。

以下のテストはすべて失敗しました。つまり、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) の制限ですか、それとも別の方法で選択できますか?

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

編集: 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')]")
4

2 に答える 2

2

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

Selenium.IsElementPresent("//option[text()='Third option']");
于 2009-08-05T02:26:54.053 に答える
0

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

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

ステップ 2: 特定のオプション (「3 番目のオプション」) がドロップダウンに表示されている天気を確認します。

for(文字列オプション:オプション)

{

if(!option.equals("3 番目のオプション"))

不合格;

そうしないと

合格;

}

于 2014-04-04T07:41:26.857 に答える