org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

前端 未结 7 1637
终归单人心
终归单人心 2020-12-30 13:33

I am trying to execute below Selenium Web driver script, But I am getting org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may n

相关标签:
7条回答
  • 2020-12-30 14:07

    Finally this worked for me. Element is not currently visible and so may not be interacted with.

    Initially it was like test was successful only 2 of 5 times. Was not sure how it was working sometimes and others not.

    Worked by reducing the security settings in IE. Enable all activeX controls. Enable scripts and IFRAMES also. Some of these will warn to put computer at risk, but it was the only solution I had. Introduce Explicit wait by using presenceOfElementLocated instead of visibilityOfElementLocated at every point where page load takes time.

        WebDriverWait wait = new WebDriverWait(driver,30);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='campaignListTable']")));   /*examining the xpath for a search     
        box*/
        driver.findElement(By.xpath("//*[@id='campaignListTable']")).sendKeys("TEXT");   /*enter text in search 
        box*/
    
    0 讨论(0)
  • 2020-12-30 14:07

    I guess you are trying to click on hyperlinks, if you are getting 'ElementNotVisibleException' this means that elements might be hidden. Does it take long time for the elements with locator 'a.uiv2-add-button.a2c' to render on the UI after you select a Category from the left panel? If yes than interaction wiith non visible elements will always throw 'ElementNotVisibleException'

    0 讨论(0)
  • 2020-12-30 14:09

    Just put the thread to sleep for some mil seconds

    Thread.sleep(5000);
    WebElement zoneName=driver.findElement(By.xpath("//*[@id=\"zoneName\"]"));
    zoneName.sendKeys("kandy");
    
    0 讨论(0)
  • 2020-12-30 14:12

    Not sure what your requirement is. But, couple of things to keep in mind.

    1. Selenium may find the element that meets same criteria but they are hidden
    2. Even if element is not hidden it may not be in a ready state to accept any interaction.

    if you know for sure the element is not hidden then you can use the following wait for the element to be visible

     new WebDriverWait(Driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible("your selector"); 
    
    0 讨论(0)
  • 2020-12-30 14:16

    To handle it , you can use explicit wait function in selenium to locate element. Most of the time it works.

    0 讨论(0)
  • 2020-12-30 14:19

    For some browsers it happens that once mouse hover action is performed, but the menu list disappear quickly before Selenium identify the next sub menu item. In that case it is better to use perform() action on the main menu to hold the menu list till the time Selenium identify the sub menu item and click on it.

    Here

    WebElement xWL = driver.findElement(By.xpath("x path text"));
    
    Actions xAct = new Actions(driver);
    

    Instead of this:

    xAct.moveToElement(xWL).build().perform();
    

    Below code will resolve the "element not visible" issue

    xAct.moveToElement(xWL);
    xAct.click();
    xAct.perform();
    
    0 讨论(0)
提交回复
热议问题