2009-08-05 6 views
1

私はC#でSelenium RCを使っていくつかの自動対話テストを行っていますが、不安を抱えています。私はオプションの「第三の選択肢は、」ページの上に存在することを確認するためにテストしたいSelect Optionのテキスト(C#)を使用してSelenium.IsElementPresent

<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> 

は、このHTMLを考えます。

次のテストはすべて、すなわち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')]") 

はそれはセレン(RC/.NET)の制限であるか、それを選択する別の方法は何ですか?

ps。私はオプションの値を使ってテストできることは分かっていますが、それは変わるかもしれませんし、テキストは明らかにそうではありません。

EDIT: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')]") 

答えて

2

私のXPathは少し錆びですが、あなたは試してみました...

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

PEBKACエラー、私の悪い。セレンは私が思っていたサイトとは異なるサイトをロードしていました。とにかくあなたには正しい答えが返ってきます:-) – Charlino

0

ステップ1:

ドロップダウンのすべてのオプションを取得します

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

ステップ2:天気の確認ドロップダウンに特定オプション(「第3オプション」)があります。 (文字列オプション:オプション)用

(!option.equals( "第三の選択肢"))であれば

{

FAIL。

else

パス;

}

関連する問題