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

前端 未结 11 1149
死守一世寂寞
死守一世寂寞 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:38

    Here is a summary of things you can do to tackle the problem (examples in Protractor/Javascript):

    • maximize the browser window (on Chrome+Mac, currently you have to do it differently):

      browser.driver.manage().window().maximize();
      
    • verify that there are no other elements matching the locator. You can get this error if there is an another element matching the locator that is actually invisible.

    • wait for the element to be clickable:

      var EC = protractor.ExpectedConditions,
          elm = element(by.id("myid"));
      
      browser.wait(EC.elementToBeClickable(elm), 5000);
      
    • scroll into view of the element:

      var elm = element(by.id("myid"));
      browser.executeScript("arguments[0].scrollIntoView();", elm);
      
    • click via javascript:

      var elm = element(by.id("myid"));
      browser.executeScript("arguments[0].click();", elm);
      
    • move to element and click via "browser actions":

      var elm = element(by.id("myid"));
      browser.actions()
          .mouseMove(elm)
          .click()
          .perform();
      

提交回复
热议问题