How I can avoid “Element is not currently visible and so may not be interacted with ” Selenium Webdriver

前端 未结 11 1127
死守一世寂寞
死守一世寂寞 2020-12-16 14:02

Am using selenium webdriver 2.210 + JAVA for testing.I have a sample code for selecting all mails in gmail.But the code throws an \"Element is not currently visible and so m

相关标签:
11条回答
  • 2020-12-16 14:57
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("document.getElementById('id').setAttribute('visibility', 'true');");
    
    driver.findElement(By.id("id")).click();
    

    by changing the visibility of the element you can perform your action. you can either click with selenium or with JavascriptExecutor

    0 讨论(0)
  • 2020-12-16 14:57

    Its weird but i have to set the browser size explicitly in Java.

    driver.manage().window().setSize(new Dimension(1000, 800));

    0 讨论(0)
  • 2020-12-16 14:59

    I'm not sure, but every watir-webdriver element has the - (Object) wait_until_present(timeout = 30) method.

    if this step is optional, you should check for visibility:

    element = driver.findElement(By.xpath("//div[@class = 'T-Jo-auh']"));
    
    if (element.isDisplayed()) {
      element.click();
    }
    

    Please note, I'm not a java guru, and the code above was not tested. Give it a try.

    0 讨论(0)
  • 2020-12-16 15:00

    Are you sure you're looking at the right element? I had a similar problem and it turned out there were two similar elements on the page, one visible and the other not. The FindElement function was returning the one that wasn't visible.

    I solved this by using FindElements instead of FindElement and then using Linq to extract the one that was visible.

    0 讨论(0)
  • 2020-12-16 15:04

    PhantomJS users should watch for the maximize-window answer. There is a good chance that a javascripted dialog box is thought to be outside the viewport even when a screenshot shows it to be fully visible. Since it is clearly visible some scroll-into-view action does not change anything, and all the other actions are useless as well. (Same for other browsers based on the WebKit engine, e.g. on MacOS Safari and old Chrome)

    0 讨论(0)
提交回复
热议问题