Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I tried everything: click, send, etc.

Below is my code:

WebElement element = ((WrapsDriver) selenium)
  .getWrappedDriver().findElement(By.xpath(LOGOUT_XPATH));
element.sendKeys(Keys.ENTER);

try {
  Thread.sleep(500);
} catch (InterruptedException e) {}

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

moveTo.moveToElement(element).click().build().perform();

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

Help is needed.

share|improve this question

closed as not a real question by user246, Sam Woods, corsiKa Nov 6 '12 at 22:08

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

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
add comment

1 Answer 1

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)
  .getWrappedDriver().findElement(By.xpath(LOGOUT_XPATH));
element.click();

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.

share|improve this answer
add comment

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