I tried everything: click, send, etc.

Below is my code:

WebElement element = ((WrapsDriver) selenium)

try {
} catch (InterruptedException e) {}

Actions moveTo = new Actions(
  ((WrapsDriver) selenium).getWrappedDriver());


But when I executed it, it works sometimes and does not work at other times.

Help is needed.

  • 1
    What exactly are you trying to do? From what I can tell you are pressing "Enter" with the focus on a logout link or button, and then trying to move the mouse to the same element and click it? You also have a try/catch around a sleep statement which won't ever catch anything... Maybe you can add more explanation as to what you are trying to do and what specifically is not working. Have you tried just executing the click function and not using the Actions class? – Sam Woods Aug 16 '12 at 17:27

The above doesn't look like what you intend to do, you are sending an ENTER keystroke to the logout element, waiting for 0.5 seconds (no need to wrap that in a try / catch as the sleep should not fail to execute), then you are moving the mouse to the element and then trying to click it.

Only one of the above should be necessary if this is a normal button or link, and it should be possible by simply calling click().

Please let us know what exception is thrown if you call:

WebElement element = ((WrapsDriver) selenium)

If an ElementNotVisible exception is thrown, or more than one element was found, you may be trying to interact with a hidden element, so make sure this is the only logout element matching your XPath, and that this one is visible - the Firefox plugin 'XPath Checker' is very useful for writing and checking XPaths in real time.

It may be useful to write some debug information to the console if you are still stuck. If element.Displayed is false, WebDriver will not be able to click it, so you know you are trying to click the wrong element if you can see it at the time.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.