How to scroll down to a particular position in a webpage

Hello,

I have a web page, where I need to click on a particular element, but the element will be visible only after scroll down in the page. Also the mouse need to be pointed on the left side of the page in order to make the scroll action. The pages are shown below.

after login to the page, the page looks like this

now i need to take the cursor to the left side (the black colour area) inorder to scroll down and get the label manage emplyee as showed below.

image

I have used scroll to element but that didnt work throwing error as Unable to click on object ‘Object Repository/Page_App4Office - root/span_Manage Employee’ (Root cause: org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point

i tried wait for element visible/clickable but that didnt work.

please suggest

thanks,
neethu

Perhaps use WebUI.mouseOver() over some element on the left side of the screen before scrolling?

1 Like

These are a couple of helpers I haven’t used in a while – maybe they’ll help?

  /**
   * Hover over an element.
   * @param selector (String) CSS selector for the element.
   */
  static void Se_hover(String selector) {
    WebUI.comment('Se_hover hovering ' + selector)
    WebDriver driver = DriverFactory.getWebDriver()
    WebElement elem = driver.findElement(By.cssSelector(selector))
    WebUI.executeJavaScript('arguments[0].scrollIntoView(true)', Arrays.asList(elem))
    Actions act = new Actions(driver)
    act.moveToElement(elem).build().perform()
    WebUI.comment('Success: ' + selector + ' hovered!')
  }

  /**
   * Hover over an element then click it.
   * @param selector (String) CSS selector for the element.
   */
  static void Se_hoverClick(String selector) {
    WebUI.comment('Se_hoverClick hoverClicking ' + selector)
    WebDriver driver = DriverFactory.getWebDriver()
    WebElement elem = driver.findElement(By.cssSelector(selector))
    WebUI.executeJavaScript('arguments[0].scrollIntoView(true)', Arrays.asList(elem))
    Actions act = new Actions(driver)
    act.moveToElement(elem).click(elem).build().perform()
    WebUI.comment('Success: ' + selector + ' hoverClicked!')
  }

Hello,

I tried this option but no luck. The pointer goes to that element on left side but the scroll still not working. I tried some simple java scripts like scroll to view e.g WebUI.executeJavaScript(‘document.getElementById(‘manageEmployeePageId’).scrollIntoView()’, null), but nothing worked. Unfortunately i am unable to understand the solution provided by @Russ_Thomas, is there any simple way?

Hi @neethu73

@Russ_Thomas uses this:

If you are not familiar with the CSS selector and want to use xpath instead, then modify it to this:
WebElement elem = driver.findElement(By.xpath(selector))

To test these functions, create a custom keyword and put these functions into them, then you can call them in your test case.

Regards !

3 Likes