2

For this line,

driver.findElement(By.name("importbutton")).click();

It is throwing exception:

Element is not currently visible and so may not be interacted with Command duration or timeout: 20.08 seconds.

The following is the html code for above,

<div class="text-center msg">
<button class="btn-w center-block btn btn-default reveal" ng-click="gplus_login()" type="button" name="importbutton">Import Gmail Contacts</button>
</div>

Can any one help me?

1
  • You need to have some kind of wait. Refer my answer. Commented Sep 24, 2015 at 10:21

2 Answers 2

3

Include an implicit or explicit (favorably, the later), before this click statement.

This is an example of how you use Explicit wait :

WebdriverWait wait1= new WebDriverWait(driver,30);
WebElement ele= wait.until(ExpectedConditions.visibilityof(elementtobechecked);

then include your click statement

driver. findElement(By.name("importbutton")).click();

If you want to use implicit wait (which I wouldn't recommend), then you can use :

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

You can use the Selenium documentation to refer more.

Here is a good example.

-1
 //driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
    Thread.sleep(2000);
    if(driver.findElement(By.name("importbutton")).isDisplayed())
    system.out.Println("test passed");
    driver.findElement(By.name("importbutton")).click();
    Else
    system.out.Println("test Fail")

Try this you might get Successs

6
  • This contains two anti-patterns. 1. ImplicitWait, better is to use an Explicit wait, because implicitwait adds a wait for each Selenium findElement and more, which slows down your tests. 2. Thread.sleep, you should never need this if you use Explicit waits. Commented Sep 24, 2015 at 15:55
  • i said use anyone java sleep method or implicit wait Commented Sep 25, 2015 at 4:48
  • This answer can not be Downvote. Because last possible solution is Thread.sleep(milisecond); May be this is right answer.
    – Sagar007
    Commented Sep 26, 2015 at 11:19
  • Sleep is never the answer, it will just create the risk of flickering tests and wasted time when figuring out why the test is failing. I cannot come up with a situation where its not possible to use an explicit wait, where you wait for an element to be visible, in a certain state or not visible at all. Colleague's using sleeps and implicit waits have wasted a lot of my time already, I suggest you never use either of them, just try to solve the problem as if they do not exist. This is similar to using GOTO in your code, it might have it uses, but regularly this is a very bad practise. Commented Sep 26, 2015 at 13:38
  • @Niels van Reijmersdal hi i know you might be right, i tried many in built wait commands like implicit,explicit,fluent wait commands are didnt work for me when iam using appium to automate an ios app. i think you may be beginner in case of app automation.... Commented Sep 28, 2015 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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