Sunday, 31 July 2022

Selenium How To Search in Scrollable Web Table | Handle / Scroll Down WebTable in Selenium Webdriver

                 In this post, we will see Selenium How To Search in Scrollable Web Table | Handle / Scroll Down WebTable in Selenium Webdriver 


Program Code (SearchInWebtable.java) :

package main;


import java.time.Duration;

import java.util.List;


import org.openqa.selenium.By;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class SearchInWebtable {


public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://mdbootstrap.com/docs/b4/jquery/tables/scroll/");

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

List<WebElement> l=driver.findElements(By.cssSelector(".table-wrapper-scroll-y.my-custom-scrollbar.mb-3.ps.ps--active-y td:nth-child(2)"));


System.out.println(l.size());

JavascriptExecutor js=(JavascriptExecutor)driver;

int scrollcount=50;

int count=0;

for(WebElement i: l)

{

if(i.isDisplayed())

{

if(i.getText().equals("Mark"))

{

count++;

}

}

else

{

String scroll="document.querySelector('.table-wrapper-scroll-y.my-custom-scrollbar.mb-3.ps.ps--active-y').scrollTop="+scrollcount;

js.executeScript(scroll);

if(i.getText().equals("Mark"))

{

count++;

}

scrollcount=scrollcount+50;

}

}

System.out.println("The number of times Mark has appeared="+count);

driver.quit();

}


}


Watch Following Video:


Watch on YouTube: https://www.youtube.com/watch?v=NE80x6BaDcg

No comments:

Post a Comment