【发布时间】:2018-01-09 09:01:13
【问题描述】:
移动到下拉列表中的值后,我想使用操作类来获取它。下面是我写的代码。我正在尝试打印下拉值。下拉的 HTML 标记是输入(选择我有代码)。请帮帮我
public static void caseSearch()
{
try
{
Actions a=new Actions(driver);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
logger.info("clicking on cases tab :: ");
driver.findElement(By.xpath(loader.getProperty(Constants.CaseTab))).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement ele=driver.findElement(By.xpath(loader.getProperty(Constants.CaseSearch)));
ele.click();
for(int i=0;i<=20;i++)
{
//i want to print the first value of dropdown in console
a.sendKeys(Keys.DOWN,Keys.DOWN,Keys.DOWN).build().perform();
String value=ele.getText();
System.out.println("value is = "+value);
a.sendKeys(Keys.DOWN,Keys.DOWN).build().perform();
Thread.sleep(3000);
a.sendKeys(Keys.ENTER).build().perform();
}
}
catch(Exception e)
{
logger.info("case search method is not executed :: " +e);
}
}
【问题讨论】:
-
您是否需要获取所有可用选项是带有选择/选项选项卡的下拉菜单?
-
是的。但标签是输入。
-
您的代码得到的错误消息或输出是什么?
-
实际上它打印的是空值而不是下拉值。这就是问题所在。没有错误抛出
-
我可以要网站的网址和详细信息吗?
标签: selenium selenium-webdriver action