Selenium: How can I make WebDriver ignore "Element is not visible" error?
I'm using Selenium WebDriver (v开发者_C百科2.5.0). I get this error when I use a 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 I mouse hover on an element, the element being clicked becomes visible. Is there any way to check whether something is visible or not?
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()
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();
精彩评论