Reputation: 1763
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;">
Upvotes: 5
Views: 17773
Reputation: 955
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.
Upvotes: 0
Reputation: 2981
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);
Upvotes: 7
Reputation: 474161
A list of things that usually help in cases like this:
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")));
Upvotes: 3