skip to Main Content

I have to click at an element which is intercepted by other element, so what i’m doing is that, I’m trying to scroll down the Vertical scroll bar and try to click my target element, so to scroll this i’m using the below code

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollBy(0, -800)", "");

But the above code is not scrolling down the scroll bar

Note: i also tried to movetoelement. That is also not working, please help me with your solutions

action.moveToElement(seatLayout.seat_A16);
Thread.sleep(2000);
seatLayout.seat_A16.click();

2

Answers


  1. To scroll down:

    ((JavascriptExecutor)driver).executeScript("window.scrollBy(0, 800)", "");
    

    To scroll up:

    ((JavascriptExecutor)driver).executeScript("window.scrollBy(0, -800)", "");
    

    To scroll the element within the viewport:

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

    References

    You can find a couple of relevant detailed discussions in:

    Login or Signup to reply.
  2. you can also use this method

    public static void scrollToTheBottom() {
            ((JavascriptExecutor)driver).executeScript("window.scrollTo(0, document.body.scrollHeight * 0.9)");
        }
    

    here 0-1 is the height of the page. I have selected 0.9 for my project

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search