1
  • As a user
  • When I go to a page
  • Then there is an element that scrolls down into view

There is a link I want to click on that element. Sometimes it will work but how do I wait for it to finish scrolling down and then click on the element?

Thread.sleep(1000) works but I want to know is there a better approach?

Tools I am using:

Java
Selenium 
akshay patil
  • 670
  • 7
  • 20
user2879680
  • 71
  • 1
  • 5
  • 2
    This scroll is performed by Selenium or how? Can you add some code to see how you try to perform click on element? – KunLun Feb 14 '19 at 11:10

1 Answers1

2

Use webdriver wait until the element visible or click able.Try the below code.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Id here"))).click();

Or

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.id("Id here"))).click();

Please Note: Instead of ID you can put any locator like xpath,class,CSS.I have provided one example of ID here.

KunduK
  • 32,888
  • 5
  • 17
  • 41