使用java从组合框硒驱动程序中选择一个项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18457503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selecting an item from a combo box selenium driver with java
提问by Eshan Liyanagama
I tried to select an item from a combo box through selenium driver with java.But it didn't work.
我试图通过带有 java 的 selenium 驱动程序从组合框中选择一个项目。但它没有用。
this is my code...
这是我的代码...
combo box list={NIC,NAME,AGE}
combo box list={NIC,NAME,AGE}
driver.findElement(By.xpath("//div[@id='views/div/select']/label")).sendKeys("NIC");
driver.findElement(By.xpath("//div[@id='views/div/select']/label")).sendKeys("NIC");
采纳答案by Santoshsarma
In WebDriver there is separate Class (Select) is there to deal with Combo lists.
在 WebDriver 中,有单独的 Class ( Select) 用于处理组合列表。
Use below logic to select options from pick list fields
使用以下逻辑从选择列表字段中选择选项
Select select=new Select(driver.findElement(By.xpath("//div[@id='views/div/select']"));
select.selectByVisibleText("NIC");
or
select.selectByIndex(0);
or
select.selectByValue("value");
Refer this postfor more info regarding Select class.
有关 Select 类的更多信息,请参阅此帖子。