Selenium Webdriver: Element Not Visible Exception

Nik_stack picture Nik_stack · Mar 2, 2015 · Viewed 64.6k times · Source

Here is my code to click a simple login button on this Website

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;    
import org.openqa.selenium.WebDriver;    
import org.openqa.selenium.firefox.FirefoxDriver;    

public class Reports {

    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();
        driver.get("https://platform.drawbrid.ge");
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        driver.findElement(By.xpath(".//*[@id='_loginButton']")).click();

    }
}

I am getting following error:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 2.05 seconds

Answer

Dmitry Shyshkin picture Dmitry Shyshkin · Mar 3, 2015

You have two buttons with given xpath on this page, first is not visible, thats why you are getting ElementNotVisibleException

One is under <div class="loginPopup">

Second (the one you need) is under <div class="page">

So change your xpath to look like this, and it will fix your problem:

By.xpath("//div[@class='page']//div[@id='_loginButton']")