Element not visible Selenium/C#

17,204

Solution 1

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);

Solution 2

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")));
    
Share:
17,204
Naughty Ninja
Author by

Naughty Ninja

Updated on June 04, 2022

Comments

  • Naughty Ninja
    Naughty Ninja about 2 years

    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;">