Selenium: How can I make WebDriver ignore “Element is not visible” error?

后端 未结 2 1116
天涯浪人
天涯浪人 2020-12-16 04:23

I\'m using Selenium WebDriver (v2.5.0). I get this error when I use a driver.click(...)\" command

Element is not currently visible and so may n         


        
相关标签:
2条回答
  • 2020-12-16 04:54

    Your best solution is to not use the click() method but to implement Actions and have selenium (via webdriver) simulate the mouse moving over the element to activate the events which then make the element clickable/enabled. once you have activated the element, then perform the click() method as needed. I am assuming that the element is disabled making it not clickable in the first place.

    Establish your element you could also use RenderedWebElement which has a hover() method then you wouldn't need to create the following Actions object however it may not work depending on how the application is designed with native events. Try both see which works best and is most elegant.

    WebElement element = driver.findElement(By.id("element_id"));
    

    Create a new actions object backed by the webdriver

    Actions actions = new Actions(driver);
    

    Move the cursor to the element - this will "activate" your element to be clickable

    actions.moveToElement(element).perform();
    

    Verify the element is now clickable or "enabled"

    assertThat(element.isEnabled());
    

    Now perform the click action

    element.click();
    
    0 讨论(0)
  • 2020-12-16 05:14

    You can do it via actions. To achieve what you want, using the Python Webdriver client, but the principle is the same.

    ActionChains(driver).move_to_element(driver.find_element(By.ID, 'Foo'))\
      .click(driver.find_element(By.Name, "Bar"))\
      .perform()
    
    0 讨论(0)
提交回复
热议问题