我正在将我的selenium 1代码转换为selenium 2,并且找不到任何简单的方法来在下拉菜单中选择标签或获取下拉列表的选定值.你知道如何在Selenium 2中做到这一点吗?
以下是两个在Selenium 1中有效但在2中不起作用的语句:
browser.select("//path_to_drop_down", "Value1");
browser.getSelectedValue("//path_to_drop_down");
Run Code Online (Sandbox Code Playgroud) 如何使用带有Java的Selenium WebDriver从性别下拉列表中选择项目(例如男性,女性)?
我试过这个
WebElement select = driver.findElement(By.id("gender"));
List<WebElement> options = select.findElements(By.tagName("Male"));
for (WebElement option : options) {
if("Germany".equals(option.getText()))
option.click();
}
Run Code Online (Sandbox Code Playgroud)
我上面的代码不起作用.
我试图单击一个按钮“复制地址”,然后单击下拉菜单项“发货至开票”选项。我可以按ID单击按钮,但是我的下一行脚本会引发错误,这就是我所拥有的-
click_element(@driver, :id, 'copyAddress')
@driver.find_element(:class, 'dropDownMenu')
#select(@driver, :class, 'dropDownMenu', 'Billing to Shipping')
#@driver.find_element(:class, 'dropDownItemOver')
#select(@driver, :class, 'dropDownItem', 'Billing to Shipping')
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经尝试了所有这些方法,但是没有运气。
任何帮助...。谢谢