Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element not visible Selenium/C#

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;">
like image 876
Naughty Ninja Avatar asked Aug 04 '15 14:08

Naughty Ninja


1 Answers

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);
like image 74
aholt Avatar answered Nov 14 '22 22:11

aholt