0

I am using Java 7, Firefox, with Selenium 2.30 0 and am getting the following error:

ElementNotVisibleException: Element is not currently visible and so may not be interacted with

Now this is what I am doing:

driver.findElement(By.xpath("//*[@id='Menu1']/li[3]/a")).click();
driver.findElement(By.xpath("//*[@id='Menu1']/li[3]/ul/li[5]/a")).click();

I am running through this in debug mode with IntellIJ so I don't think it is a timing problem as I am going pretty slow. The first find element works great and I can see the menu drop down with the 5 items to select / click. Now when I get to the second step I get an error. Is there something I need to do in order to make a WebElement visible to the driver?

pb2q
  • 58,613
  • 19
  • 146
  • 147
cbohannon
  • 231
  • 8
  • 18
  • what happens when you try to select li[4]/a or li[3]/a? Have you double checked your xpath? – Farlan Mar 09 '13 at 01:54
  • Thank yo so much for the input. I did a little more searching, something that I should have done to begin with, and found this: http://stackoverflow.com/questions/6245690/mouse-hover-on-webelement-using-selenium-2-in-java which seems to get me where I want to go! – cbohannon Mar 09 '13 at 15:03

2 Answers2

0

There is sometime issue while selecting element from drop down list. There are various solutions, check if something work out for you:

1- Use clickAt.

2- Use fireevent(focus) and then click. Sometime it happens some element in back ground is getting loaded, when it gets loaded, focus move there hence elementNotVisible error.

3- Use mouseDownRight.

Check them out. Update the question if you have more observations.

Amit Shakya
  • 1,396
  • 12
  • 27
0

A stale element reference exception is thrown in one of two cases, the first being more common than the second: The element has been deleted entirely. The element is no longer attached to the DOM.

The most frequent cause of this is that page that the element was part of has been refreshed, or the user has navigated away to another page. A less common, but still common cause is where a JS library has deleted an element and replaced it with one with the same ID or attributes. In this case, although the replacement elements may look identical they are different; the driver has no way to determine that the replacements are actually what's expected.

If the element has been replaced with an identical one, a useful strategy is to look up the element again. If you do this automatically, be aware that you may well be opening your tests to a race condition and potential flakiness. For example, given the code

WebElement element = driver.findElement(By.id("example"));
String text = element.getText();
  • Note that [link-only answers are discouraged](http://meta.stackoverflow.com/tags/link-only-answers/info), SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Dec 30 '13 at 17:58