I am getting this error "Element is currently not visible" when I try to input into textbox which is visible I've created a script to signup and I am getting this error randomly sometimes on "password" textbox sometime on "re-password" text box I don't know what is the reason? following is code snippet

ExcelRead objExcel = new ExcelRead("D:\\K - Selenium\\SeleniumWorkspace\\EMAILGENERATOR\\src\\testData\\EmailGeneratorData.xls","CreateAccount");

        int iNoofRows = objExcel.rowCount()-1;

        for(int i =1;i<iNoofRows;i++)
        driver.findElement(By.xpath(".//*[@id='idb']")).sendKeys(objExcel.getCellData("FName", i));

        driver.findElement(By.xpath(".//*[@id='idd']")).sendKeys(objExcel.getCellData("LName", i));
        driver.findElement(By.xpath(".//*[@id='idf']")).sendKeys(objExcel.getCellData("Gender", i));
        driver.findElement(By.xpath(".//*[@id='id14']")).sendKeys(objExcel.getCellData("Month", i));
        driver.findElement(By.xpath(".//*[@id='id11']")).sendKeys(objExcel.getCellData("Day", i));
        driver.findElement(By.xpath(".//*[@id='id15']")).sendKeys(objExcel.getCellData("Year", i));
        driver.findElement(By.xpath(".//*[@id='id16']")).sendKeys(objExcel.getCellData("Country", i));
        driver.findElement(By.xpath(".//*[@id='id1e']")).sendKeys(objExcel.getCellData("Email", i));
        driver.findElement(By.id("id28")).sendKeys(objExcel.getCellData("Password", i));
        driver.findElement(By.xpath(".//*[@id='id2b']")).sendKeys(objExcel.getCellData("Re-Password", i));
        //Security Q
        driver.findElement(By.id("id33")).sendKeys(objExcel.getCellData("SecQ", i));
        driver.findElement(By.id("id39")).sendKeys(objExcel.getCellData("Ans", i));

        //Button Click
  • using sleep can make the test brittle. can you use a wait until element visible? – David Cain Apr 5 '16 at 23:04

I would suggest not to use Thread.sleep() method, instead you can use the implicit wait, add following line of code after driver is declared.

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

and remove all Thread.sleep() methods from the code.

Difference between implicit wait and Thread.sleep() is Thread.sleep() method will wait until given time then it will search for the element which unnecessarily increase the execution time, where as implicit wait will keep on searching for the element until given time then it will throw an exception if element is not found and if element is found it will continue the execution immediately

| improve this answer | |

There is several issues here.

An implicit wait would do far better than the Thread.sleep()

Using Xpath to search by id. Just use by.id() it will be far faster

The ids, to me, appear to be dynamically created which will cause them to break. If the rest of the script works I would presume this is not the issue though.

Use new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(ElementBy)) to wait x (10 in this case) seconds until the element is visible

Use the new Actions(driver).moveToElement(el) API to ensure the element is scrolled into the view


I instantiated the above as new Objects so the code is directly usable. I would recommend putting them into a shared/helpers class to avoid having to deal with them on a regular basis. With this way, they just work every time and are easy.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.