从选择标记中选择值时引发ElementNotInteractableException

This is the DOM structure. DOM

Any of the following operations are throwing org.openqa.selenium.ElementNotInteractableException

selectFileStatus.selectByIndex(2);

要么

selectFileStatus.selectByVisibleText(valueToSelect);

实例化是这样的。

Select selectFileStatus = new Select(wait.until(ExpectedConditions.elementToBeClickable(By.xpath(
                property.getPropertyObject(propFileDetailClaimReview).getProperty(propertyDropdownFileStatus)))));

并且XPATH在浏览器中进行了测试。

//span[contains(text(), 'File Status')]/parent::label/following-sibling::select

有趣的是,读取操作可以正常工作。

List<WebElement> allOptions = selectFileStatus.getOptions();
System.out.println("*** Values of the dropdown...");
for(WebElement eachOption : allOptions)
    System.out.println(eachOption.getText());

As this <select> tag looks like a real HTML object, what can be the problem here?

评论
  • 哎呦喂
    哎呦喂 回复

    我使用示例DOM进行了尝试,并且能够使用JS执行器进行选择

    driver.get("file:///C:/Users/Wilfred/Desktop/Stack.html");
    
            Select selectFileStatus = new Select(driver.findElement(By.xpath("//*[@id='2']")));
    
            List<WebElement> allOptions = selectFileStatus.getOptions();
            System.out.println("*** Values of the dropdown...");
            for (WebElement eachOption : allOptions)
                System.out.println(eachOption.getText());
    
            int index = 2;
            JavascriptExecutor js = (JavascriptExecutor) driver;
            String script = "return document.getElementById(2).selectedIndex = '" + index + "';";
            js.executeScript(script);
    
    <html>
       <body>
          <label>File Status : </label>
          <select id = "2">
             <option value="0">All</option>
             <option value="1">First</option>
             <option value="2">Second</option>
             <option value="3">Third</option>
          </select>
    </html>