0

My webpage's scrollbar is hidden but appears when I move my cursor and gets hidden again.

What I need is to scroll down the webpage to hover over an element and then click on a button (button appears when hover over the element).

I tried using javascript, actions() but those didn't make me happy.

((JavascriptExecutor) driver).executeScript("window.scrollTo(0,100);");

5
  • can you paste your code here ? Also you can try to press page down button if you want Commented Nov 8, 2019 at 7:24
  • public void scrollIntoElement() { ((JavascriptExecutor) driver).executeScript("window.scrollTo(100,0);"); } And I cannot try pressing the page down button as I don't have any element to send keys, I mean no any text field elements. Commented Nov 8, 2019 at 8:22
  • Alright, so you cant use action class because it required element for a moment. Commented Nov 8, 2019 at 8:28
  • if possible please provide your site will quickly check Commented Nov 8, 2019 at 8:28
  • @Rock I tried the following as well. 'public void scrollIntoElement(WebElement element) throws InterruptedException { ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);", element); }' Commented Nov 8, 2019 at 8:35

2 Answers 2

0

To scroll down please refer below code:

  JavascriptExecutor js = (JavascriptExecutor) driver;

 // This  will scroll down the page by  1000 pixel vertical     
     js.executeScript("window.scrollBy(0,1000)");
Sign up to request clarification or add additional context in comments.

1 Comment

give your site if possible
0

when you know which element you are looking for, you can scroll down directly to the element like this:

suppose your element is as below:

WebElement element = driver.findElement(By.id("id_of_element"));

now you can scroll to element :

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

3 Comments

I tried this, but this isn't working, neither error messages nor scroll.
is it possible for you to mention the website?
I found another solution here. You can try it: sqa.stackexchange.com/a/9660/40543

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.