Piyush Garg
Piyush Garg

Reputation: 37

how we perform scroll in table

I want to perform scroll down in web table but its not performing with a logic

JavascriptExecutor jse1 = (JavascriptExecutor) driver;
jse1.executeScript("window.scrollBy(0,200)");          

Upvotes: 0

Views: 11134

Answers (2)

Anwar Jamil Khan
Anwar Jamil Khan

Reputation: 11

Use EventFiringWebDriver.

Steps:

  1. Launch the Web Application.
  2. Locate the WebTable.
  3. Use executeScript.

Below is the code:

eventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(driver);
eventFiringWebDriver.executeScript("document.querySelector('.ui-grid-viewport.ng-isolate-scope').scrollTop=6000");

Upvotes: 1

iamkenos
iamkenos

Reputation: 1566

You can make use of Selenium's Actions class.

Steps:

  • Create your WebDriver instance

    WebDriver driver = new ChromeDriver();
    

  • Create your Actions instance by passing the driver instance as parameter.

    Actions actions = new Actions(driver)
    

  • Locate your element (table you want to scroll to)

    WebElement element = driver.findElement(By.xpath("tableXpath"));
    

  • Move to the element

    actions.moveToElement(element).perform();
    

    Upvotes: 0

  • Related Questions