Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从下拉列表中选择仅需要从下拉列表中选择值的值?_Java_Selenium - Fatal编程技术网

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

Java 如何从下拉列表中选择仅需要从下拉列表中选择值的值?,java,selenium,Java,Selenium,在我的情况下,我只能从下拉列表中选择值。 作为Goibibo发送密钥与我从下拉列表中选择的不同。 那么你能帮我选择这个值吗 <input id="companyQuery" class="shadow-in tooltips fileSimilar" type="text" value="" onkeypress="javascript:populateCompanies();" data-name="company name" onfocus="if (this.value == 'Co

在我的情况下,我只能从下拉列表中选择值。 作为Goibibo发送密钥与我从下拉列表中选择的不同。 那么你能帮我选择这个值吗

<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类选择元素,但没有成功

您使用selectByValue选择下拉选项,但html代码中的值为空。所以一定要使用selectByVisibleText而不是SelectByValue

使用以下代码行:

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

您尝试过的内容,请共享该下拉列表中的html代码。@HelpingHands我编辑了我的问题,并共享了html代码。该下拉列表是否在javascript弹出窗口中?请复制下拉菜单中的html代码。我认为JS只是在您键入一些内容之后才将其添加到DOM中。