2016-12-05 6 views
-2
String city; 
Select dropdown = new Select(driver.findElement(By.id("city"))); //Selects the dropdown menu 
dropdown.selectByValue(cityName); //selects Ajax as the city from the Dropdown menu 
city = dropdown.selectByValue(cityName); 

これは私が使用しているものです。しかし、それは動作しません。私を助けてください。selenium webdriverを使用してドロップダウンで選択したオプションから文字列変数にテキストを取得するにはどうすればよいですか?

答えて

0

ドロップダウンから現在選択されているテキストを取得したい場合は、以下のように、あなたは、「getFirstSelectedOption」メソッドを使用することができますが:

String city; 
Select dropdown = new Select(driver.findElement(By.id("city")));  //Selects the dropdown menu 
dropdown.selectByValue(cityName); //selects Ajax as the city from the Dropdown menu 
city = dropdown.getFirstSelectedOption(); 

私はあなたの質問を誤解している場合、私に知らせてください。

+0

ありがとうございます! –

+0

素晴らしい。どういたしまして。私の答えを受け入れ、あなたの期待どおりに働いていればそれを有用とマークしてください:-)。 – Mahipal

関連する問題