Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Html 我正在尝试获取文本,但获取了?(值),无法单击。这是selenium中的一个下拉按钮(默认情况下,值处于选中状态) ▼ 精选公司 金库酿造公司 素食野餐 Yes酒店集团_Html_Selenium - Fatal编程技术网

Html 我正在尝试获取文本,但获取了?(值),无法单击。这是selenium中的一个下拉按钮(默认情况下,值处于选中状态) ▼ 精选公司 金库酿造公司 素食野餐 Yes酒店集团

Html 我正在尝试获取文本,但获取了?(值),无法单击。这是selenium中的一个下拉按钮(默认情况下,值处于选中状态) ▼ 精选公司 金库酿造公司 素食野餐 Yes酒店集团,html,selenium,Html,Selenium,我的代码是 <div class="select-wrapper initialized"> <span class="caret">▼</span> <input type="text" class="select-dropdown" readonly="true" data-activates="select-options-56a6924e-42d9-1f78-1b82-fe2c1cbdfbdd" valu

我的代码是

<div class="select-wrapper initialized">
  <span class="caret">▼</span>
  <input type="text" class="select-dropdown" readonly="true" 
        data-activates="select-options-56a6924e-42d9-1f78-1b82-fe2c1cbdfbdd"
        value="R3PORTS, INC">
  <select id="comp_drpdwn" class="initialized"
         data-select-id="ff6db37d-572c-bae4-7ba8-49856f516da7">
     <option value="0">Select Company</option>
     <option value="Vault Brewing Company~TI41305172">Vault Brewing Company</option>
     <option value="Vegan Picnic~TI28950835">Vegan Picnic</option>
     <option value="Yes Hospitality Group~TI09460957">Yes Hospitality Group</option>
  </select>
</div>
List out=driver.findElements(
xpath(“//div[@class='select-wrapper initialized']”);
for(网络元素tuo:out){
String test=tuo.getText();
系统输出打印LN(测试);
}

考试结果通过了,但我只得到了?(问号)。请帮助我解决我的问题

您可以使用您在评论中提到的选择下拉列表

List<WebElement> out = driver.findElements(
                                By.xpath("//div[@class='select-wrapper initialized']"));
for(WebElement tuo : out) {
    String test = tuo.getText();
    System.out.println(test);
}

您给定的HTML代码缺少选项部分,请在问题中查找更新

WebElement element = driver.findElement(By.Xpath(".//*[@id='comp_drpdwn']""));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
如果上述代码无法工作,请尝试以下代码:

String option2Select = "Vegan Picnic";

WebElement selectWrapper = driver.findElement(
            By.cssSelector("div.select-wrapper.initialized"));

// click on the ▼ to expand options
selectWrapper.findElement(By.cssSelector("span.caret")).click();

// click on wanted option
selectWrapper.findElement(By.xpath(".//option[text='" + option2Select + "']")).click()

是否要获取所选值?替换列表输出=driver.findElements(By.cssSelector(“div.select-wrapper.initialized”);请澄清您想要解析打印控制台输出中的
字符,或者您想要单击
因为
是一个特殊符号,控制台输出可以正常显示。
尝试获取文本
,但
我获取了?(值)
无法单击
。请编辑问题,将其限制为特定问题,并提供足够详细的信息,以确定适当的答案。避免同时问多个不同的问题。请参阅本页以获取澄清此问题的帮助。您的问题没有明确说明您想要什么。获取文本或单击什么?他的下拉列表不是本地的,而是css下拉列表。我们不能使用只适用于本机下拉菜单的
Select
类。@我在代码上方使用的prany显示错误,如:Element应为“Select”,但为“input”@prany更新的代码也显示错误,如org.openqa.selenium.NoSuchElementException:无法找到索引为3的选项(我正在尝试索引值为0到10)您正在使用哪种浏览器,并告知selenium版本?@Prany browser:Chrome&selenium:3.9.0以上代码不适用于我。错误,如org.openqa.selenium.ElementNotVisibleException:element notvisibleexception:element not visible给出完整的错误消息,我需要知道哪个元素不可见。
String option2Select = "Vegan Picnic";
driver.findElement(By.cssSelector("select#comp_drpdwn"));
      .findElement(By.xpath(".//option[text='" + option2Select + "']")).click()