Java 如何从selenium webdriver中的下拉框中选择值

Java 如何从selenium webdriver中的下拉框中选择值,java,selenium-webdriver,Java,Selenium Webdriver,下面是我的代码。我需要选择选项值,如value1、value2 <td class="column-label" width="50%"> <div id="divRawMaterials" name="Companies" style="position: relative"> <select name="yieldStandardDTO.rawMaterialName" size="1" onmouseover="dropdowntooltip(this);

下面是我的代码。我需要选择选项值,如value1、value2

 <td class="column-label" width="50%">
<div id="divRawMaterials" name="Companies" style="position: relative">
 <select name="yieldStandardDTO.rawMaterialName" size="1" onmouseover="dropdowntooltip(this);" onmouseout="return nd();" 
nmousedown="showtooltip(this);" onchange="chooseYieldItems('name');" style="width:205px;" class="select"><option value="">-- Select --</option>

<option value="010080159">value1</option>
<option value="010080024">value2</option>
<option value="010080071">value3</option>
<option value="010030014">value4</option>
<option value="010090009">value5</option>
及 我试过下面的方法,但不起作用。请帮我解决这个问题

  METHOD:1
  Select dropdown = new Select(driver.findElement(By.name("yieldStandardDTO.rawMaterialName")));
System.out.println(dropdown);
//dropdown.selectByVisibleText("value1");
//dropdown.selectByIndex(1);
dropdown.selectByValue("value1");

  METHOD:2
 WebElement selectMonth = driver.findElement(By.xpath("//div[@id='divRawMaterials']/select"));

List<WebElement> options = selectMonth.findElements(By.tagName("value1"));

for (WebElement option : options) {

if("Alphonso Mango".equals(option.getText()))

option.click();

  METHOD:3

WebElement hiddenWebElement =driver.findElement(By.xpath("//div[@id='divRawMaterials']/select"));
((JavascriptExecutor)driver).executeScript("arguments[0].click()",hiddenWebElement);

要显示下拉列表,您可以尝试以下操作:

((JavascriptExecutor)driver).executeScript("$('select[name=\"yieldStandardDTO.rawMaterialName\"]').click();");
现在下拉列表可见,您可以使用:

Select dropdown = new Select(driver.findElement(By.name("yieldStandardDTO.rawMaterialName")));
dropdown.selectByVisibleText("value1");

不起作用怎么办?每个方法都会出现哪些错误?org.openqa.selenium.NoSuchElementException:无法找到xpath=//div[@id='divrawmateries']/select的元素