从下拉列表中选择特定值

时间:2014-08-11 07:51:34

标签: c# selenium selenium-webdriver

我正在尝试传递国家/地区的特定值以从下拉菜单中选择 但我无法使用以下代码执行此操作:

wd.FindElement(By.Id("CountrySelector")).Click(); 
new SelectElement(wd.FindElement(By.Id("CountrySelector"))).SelectByText("Philippines-Philippine Peso(PhP)");

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我不太熟悉硒的c#实现,只是java。也许只有一些丢失的空白或类似的东西。请尝试以下方法:

WebElement webElement = driver.findElements(By.xpath("//select[@id='CountrySelector']//option[text()='Philippines-Philippine Peso(PhP)']"));
Assert.assertTrue(webElement.isDisplayed());

(对不起,它的java,也许你必须改变代码,但我想你明白了......)