Selenium: How can I make WebDriver ignore the "Element is not visible" error?

I am using Selenium WebDriver (v2.5.0). I get this error when I use the driver.click(...) command

 Element is not currently visible and so may not be interacted with Build info: version: '2.5.0', revision: '13516', time: '2011-08-23 18:30:44' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.38-10-generic', java.version: '1.6.0_26' Driver info: driver.version: RemoteWebDriver 

In the browser, when the mouse hovers over an element, the element, by clicking on it, becomes visible. Is there a way to check if something is visible or not?

+6
source share
2 answers

You can do this with actions. To achieve what you want, use 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() 
+12
source

The best solution is not to use the click () method, but to perform actions and selenium (via webdriver) to simulate mouse movement over an element to activate events that then make the element clickable / enabled. as soon as you activate the element, then, if necessary, execute the click () method. I assume the item is disabled, which makes it not clickable in the first place.

Create your own element, which you can also use RenderedWebElement, which has the hover () method, then you will not need to create the next Actions object, but it may not work depending on how the application is developed using its own events. Try both that work best and are the most elegant.

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

Create a new actions object supported by webdriver

 Actions actions = new Actions(driver); 

Move the cursor to the element - this "activates" your element for click

 actions.moveToElement(element).perform(); 

Verify that the item is now clickable or enabled

 assertThat(element.isEnabled()); 

Now do click action

 element.click(); 
+4
source

Source: https://habr.com/ru/post/896830/


All Articles