Notifications
Clear all

[Solved] Selenium: getting ElementNotVisibleException when I try to click on visible element?

3 Posts
3 Users
4 Reactions
867 Views
1
Topic starter

For some reason I'm getting ElementNotVisibleException when I try to click on visible component:

WebElement quickSearchInputEl = uiContext.waitUntilElementExists(By.name("QuickSearch"));
quickSearchInputEl.click(); // exception happens here

Screen and DOM-structure:

 image 1
1 Answer
2
Topic starter

Looks like this is some selenium issue.
There is workaround to click within field:

WebElement quickSearchInputEl = uiContext.waitUntilElementExists(By.name("QuickSearch"));
((JavascriptExecutor)cc.getDriver()).executeScript("arguments[0].focus(true);", quickSearchInputEl);
GregMerrill 2012-03-27 09:03:00

This solution looks fine, but I wonder if the focus() call really solved it? Or if that is a coincidence and it really worked because that gave it enough time to become visible? For example, I wonder if something like this would have worked just as well:

context.waitUntil(new ExpectedCondition<WebElement>() {
  @Override
  public WebElement apply(WebDriver driver) {
    return quickSearchInputEl.isDisplayed() ? quickSearchInputEl : null;
  }
});
Sean Durkin 2012-03-27 11:03:00

@greghmerrill: I think the problem is with the WebElement.click() method itself, because we had to do the same thing within TextField.setValue(); we commented out the click() call and instead used JS to focus the element before using WebElement.sendKeys().