5

I get the button element by Xpath, but when try to click on it, getting element not visible exception.

<div class="modal-footer">
   <button id="btnRegister" type="button" class="btn btn-primary btn-block">Register</button>
</div>

The parent div

<div class="modal fade in" id="registration-window" tabindex="-1" role="dialog" aria-labelledby="register-title" aria-hidden="false" style="display: block;">
threesixnine
  • 1,733
  • 7
  • 30
  • 56

3 Answers3

7

To add to the list of things you can try:

The problem may be a little more complicated than that the element is just not currently visible. There may be an invisible element in front of it that is keeping it from being visible no matter how long you wait. In which case, there are a few ways that you can still get ahold of it:

Scroll to it with javascript:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].scrollIntoView()", yourElement);

or...

Click it with javascript:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click()", yourElement);
aholt
  • 2,829
  • 2
  • 10
  • 13
3

A list of things that usually help in cases like this:

  • maximize the browser window:

    driver.Manage().Window.Maximize();
    
  • move to element before clicking it:

    Actions builder = new Actions(driver);
    builder.MoveToElement(yourElement).Click().Build().Perform();
    
  • wait for element to become clickable:

    var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
    var clickableElement = wait.Until(ExpectedConditions.ElementIsClickable(By.Id("id")));
    
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • *It didn't crash it seems like it found element and clicked on it but nothing happens. Just like it didn't click on it, any clue?* – threesixnine Aug 04 '15 at 14:19
  • @Mystia yeah, I think that js click aholt has suggested should solve the issue. – alecxe Aug 04 '15 at 14:39
0

Look at your web page in Firefox with the Firepath plugin installed. Then hit F12 to bring up the plugin, click on FirePath and type in your XPath. If you have more than 1 Matching node, then you need to change your XPath until you only have 1. If the element you are trying to click on is not surrounded in blue dashes, that means you're targeting the wrong element.

enter image description here