0

I want to scroll down using selenium webdriver but I am unable to scroll down.

I have tried javascript executor but it did not work for me.

I have tried below code to scroll down but no success:

WebDriverWait wait = new WebDriverWait (driver, 15);
      wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div/div/div/div/div/div/div/div[2]/a/img")));

      WebElement element1 = driver.findElement(By.xpath("/html/body/div/div/div/div/div/div/div/div[2]/a/img"));
      Actions builder = new Actions(driver);
      Action seriesOfActions = builder.moveToElement(element1).click().sendKeys(Keys.PAGE_DOWN).build();
      seriesOfActions.perform();

I need to scroll down to the image mentioned in the above code. But it is not working. Tried all possible ways but no use.

2
  • The xpath locator you provided seems pretty brittle. Please, share your HTML and the error you are getting. Commented May 16, 2019 at 13:08
  • What is the code that clicks the image and then pages down supposed to be doing? Typically people use JS for this... post the JS code attempt that you tried and any error messages. Commented May 16, 2019 at 14:09

1 Answer 1

1

Try using moveToElement action on tag "a". Selenium as per my knowledge does not work efficiently with tags like img, svg etc

Sign up to request clarification or add additional context in comments.

4 Comments

Can you please share any example ?
Actions actions = new Actions(driver); WebElement mainMenu = driver.findElement(By.linkText("menulink")); actions.moveToElement(mainMenu);
Thanks "Arslan" for giving pin pointed solution in very less time !!! Using link text solved my problem !!! Now i can scroll down using selenium webdriver java. Below is my updated working code. Actions actions = new Actions(driver); WebElement element1 = driver.findElement(By.linkText("View More...")); Action seriesOfActions = actions.moveToElement(element1).sendKeys(Keys.PAGE_DOWN).build(); seriesOfActions.perform();
No worries! Enjoy Selenium :)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.