使用java从硒的下拉列表中选择值的替代方法 [英] Alternative ways for selecting value from drop down list in selenium using java

查看:25
本文介绍了使用java从硒的下拉列表中选择值的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 java 从 selenium 的下拉列表中选择值时出错.

I have got an error with select the value from drop down list in selenium using java.

//Select the Warehouse
Select Warehouse= new Select(driver.findElement(By.xpath(Xpath.warehouse_SVR)));
System.out.println("Element is identified ");
Warehouse.selectByValue("3");
System.out.println("Value is selected");
Thread.sleep(1000);
js.executeScript("window.scrollTo(0,0)");

我使用了与从下拉列表中选择值相关的方法.这里我提到了 .selectByValue() 方法.即使我使用了 .selectByIndex() 或 .selectByVisibleText() 方法,我仍然遇到错误.从下拉列表中选择值的可能方法是什么?

I used the methods which are related to select the value from drop down list. Here I mentioned the .selectByValue() method. Even though I used .selectByIndex() or .selectByVisibleText() methods, still I have got the error. What is the possible way to select the value from drop down list?

这是该特定下拉列表的 Html 代码.

This is the Html code for that particular drop down list.

<select id="ctl00_cphbody_rptRNDViewer_ctl04_ctl05_ddValue" class="aspNetDisabled" style="font-family: Verdana; font-size: 8pt; width: 217px;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$cphbody$rptRNDViewer$ctl04$ctl05$ddValue\',\'\')', 0)" name="ctl00$cphbody$rptRNDViewer$ctl04$ctl05$ddValue">
<option value="1">- All -</option>
<option value="2">Damage Warehouse-1000003061</option>
<option value="3" selected="selected">Primary Warehouse-1000003061</option>
<option value="4">VAN</option>
</select>

推荐答案

  public boolean selectValueFromDropDown(String searchValue) {      

  WebElement element = driver.findElement(By.Id("ctl00_cphbody_rptRNDViewer_ctl04_ctl05_ddValue"));     
  element.click();
  element.sendKeys(searchValue);
  element.sendKeys(Keys.ENTER);
  return true;
    }

这篇关于使用java从硒的下拉列表中选择值的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆