1

I have a scenario where system needs to scroll UP to the webelement in the left panel of the page and click to perform other operations.I have tried the below ways but none of them are working.Please suggest :

1.

 WebElement element = driver.findElement(By.xpath("element"));
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
    Thread.sleep(500); 

2.

WebElement element = driver.findElement(By.xpath("element"));
 Actions actions = new Actions(driver);
        actions.moveToElement(ele);
        actions.perform();
5
  • What the error you getting? Commented Sep 11, 2019 at 9:48
  • @frianH : am getting this error " org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[text()='some text']"} " Commented Sep 11, 2019 at 9:53
  • Can you try to modify your locator to .//*[contains(text(),'some text')] Commented Sep 11, 2019 at 9:56
  • @Rahul Are you sure with your locator ? it seem like element not found in the pages. Please share html. Commented Sep 11, 2019 at 9:58
  • @frianH : It is working fine until the element is visible i.e, when other text is being added below that element , webdriver is unable to scroll up to that desired element and perform actions.sorry, html cannot be shared as it is private. Commented Sep 11, 2019 at 10:02

1 Answer 1

2

Up or Down to scrollIntoView() an element you have to induce WebDriverWait for the visibilityOfElementLocated() and you can use the following solution:

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("element"))));
Sign up to request clarification or add additional context in comments.

Comments

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.