Java webdriver: Element not visible exception

前端 未结 5 832
一向
一向 2020-12-11 05:31

I\'m having the following problem. I have a dropdown that is hidden so when I make the Select and run the test i get the following error:

 org.openqa.seleniu         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 06:22

    Since WebDriver tries to simulate real users, it cannot interact with elements which are invisible/hidden. To solve your issue, I think you would need to click on div first which will make the drop down visible and select option from the dropdown. I would recommend such an approach as opposed to pure Javascript way since it would simulate a real user. Give following a shot,

    WebDriverWait wait = new WebDriverWait(driver, 300);
    WebElement triggerDropDown = driver.findElement(By
                    .className("ui-helper-hidden"));
    triggerDropDown.click();
    WebElement selectElement = wait.until(ExpectedConditions
                      .visibilityOfElementLocated(By.id("formLevel:levels_input")));
    Select select = new Select(selectElement);
    select.selectByVisibleText("SECURITY");
    

    Edit updated the class name of triggerDropDown

提交回复
热议问题