如何从下拉列表中选择我需要从下拉列表中选择值的值?

时间:2015-06-03 09:12:32

标签: java selenium

在我的情况下,我只能从下拉列表中选择值。 发送密钥为" Goibibo"不同于我从下拉菜单中选择的内容。 那么请你帮我选一个值吗?

enter image description here

<input id="companyQuery" class="shadow-in tooltips fileSimilar" type="text" value="" onkeypress="javascript:populateCompanies();" data-name="company name" onfocus="if (this.value == 'Company Name (Complaint Against)') {this.value = '';}" name="complaintUserDTO.companyName" data-placement="right" rel="popover" placeholder="Company name" autocomplete="off" style="border-color: rgb(204, 204, 204); border-width: 1px; border-style: solid;">

GeneralMethods.driver.findElement(By.id("companyQuery")).sendKeys("Goibibo");  
            Select dropdown = new Select (GeneralMethods.driver.findElement(By.id("companyQuery")));
            dropdown.selectByValue("Goibibo");

我尝试使用Select类选择元素,但没有运气

1 个答案:

答案 0 :(得分:0)

使用selectByValue()选择下拉选项,但html代码中的值为空。所以请使用selectByVisibleText()而不是SelectByValue()。

使用以下代码行:

 WebElement element = driver.findElement(By.id("companyQuery"));
 Select selectOption= new Select(element);
 selectOption.selectByVisibleText("Goibibo");
相关问题