Selenium Webdriver: Element Not Visible Exception

微笑、不失礼 提交于 2019-11-30 14:09:52
Dmitry

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']")

There are even 3 elements with id="_loginButton" on the page, and only one is visible - the one located inside the login form, you can get it by a CSS selector:

By.cssSelector("form#_loginForm div#_loginButton")
Abinaya Veluswamy

There are 3 occurrences of id="_loginButton".

Used the id="_loginButton" under class="signIn" by cssSelector to get the exact button in the page.

By.cssSelector("div.signIn div#_loginButton")
SelThroughJava

Webdriver may throw an ElementNotVisible exception in-case there are multiple elements with the same locator and if Webdriver has already operated upon one of the element matching the locator.

In such scenarios you can first get the size of the element using

int var_ele_size= driver.findElements(By.xpath("locator")).size();

and then take the first element from the list and click on the element.

driver.findElements(By.xpath("locator")).get(var_ele_size-1).click();
Kishore Paul
public static void Listget (WebDriver driver) throws Exception 

{
    Thread.sleep(5000);
    UtilityMethod.getAppLocaters(driver, "closeicon").click();

    Actions action = new Actions(driver);
    WebElement we = driver.findElement(By.xpath("//li[@class='parent dropdown  aligned-left']"));
    Thread.sleep(5000);
    action.moveToElement(we).build().perform();

    List<WebElement>links = driver.findElements(By.xpath("//span[@class='menu-title']"));
    int total_count = links.size();       
    System.out.println("Total size :=" +total_count);           
     for(int i=0;i<total_count;i++)
        {             
            WebElement  element = links.get(i);
            String text = element.getAttribute("innerHTML");
            System.out.println("linksnameis:="  +text);

            try{
                    File src = new File("D:ReadFile.xlsx");
                    FileInputStream fis = new FileInputStream(src);
                    XSSFWorkbook wb=new XSSFWorkbook(fis);
                    XSSFSheet sh = wb.getSheetAt(0);

                    sh.createRow(i).createCell(1).setCellValue(text);

                    FileOutputStream fos = new FileOutputStream(new File("D:/ReadFile.xlsx"));
                    wb.write(fos);
                    fos.close();
                }
                catch(Exception e)
                {
                    System.out.println(e.getMessage());
                }


        }
    }
}
jacquestheron

Make sure your window on the remote server is big enough so the elements are not hidden because of space constraints ..

This worked for me: (I use c#)

driver.Manage().Window.Size = new System.Drawing.Size(1928, 1060);
Pini Amiram

You could try:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("your locator value")));

Or

wait.until(ExpectedConditions.ElementIsVisible(By.xpath("your locator value")));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!