I need your help I want to paginate through a table an store the values of it untill "Next Button" disables. Although storing values is not ossible its ok. But help me in pagination I want to click on the button it the next button untill it is not disabled .Please help me. I am on a internship
Java Code:
package Onsight.Framework;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import com.github.javafaker.Faker;
import avdhut.onsight.commonutils.BaseComponenets;
import avdhut.onsight.pageobject.HomePage;
import avdhut.onsight.pageobject.LoginPage;
import io.github.bonigarcia.wdm.WebDriverManager;
public class Webtable extends BaseComponenets {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
String urlString = "https://oinsightsvm1.westindia.cloudapp.azure.com:444/ctsOInsightsBMS/res/createReport.html";
String userEmailString = "User66";
String userPassword = "Avdhut@5201";
String titleString;
String textString="Clarita";
Faker faker = new Faker();
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
// options.addArguments("--ignore-ssl- errors=yes");
options.addArguments("--ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);
driver.get(urlString);
LoginPage loginPage = new LoginPage(driver);
loginPage.login_username(userEmailString);
loginPage.click0nsubmit();
loginPage.EnterPassword(userPassword);
loginPage.click0nsubmit();
HomePage homePage = new HomePage(driver);
// homePage.view_report_values(textString);
IsVisible(baseTableBy);
WebElement baseTable=driver.findElement(baseTableBy);
List<WebElement> table_roWebElement=baseTable.findElements(report_name_rowsBy);
for (WebElement webElement : table_roWebElement) {
if (webElement.getText().contains(report_title)) {
System.out.println(true);
IsClickable(viewBy);
System.out.println(webElement.getText());
webElement.findElement(viewBy).click();
IsClickable(view_dataBy);
driver.findElement(view_dataBy).click();
while (IsVisible(paginateBy)) {
IsClickable(paginateBy);
driver.findElement(paginateBy).click();
}
} else {
}
}
}
//tr[class='odd'] em[class='fa fa-table']
Html:
CodePudding user response:
After logging in, once you reach the table which contains the list of reports, add the below code and try:
Thread.sleep(2000);
// to close the toast message, if the toast message does not appear, comment the below line
driver.findElement(By.xpath(".//button[@class='toast-close-button']")).click();
boolean flag = true;
// below while loop will click the 'NEXT' button until it is disabled
while (flag) {
WebElement nextBtn = driver.findElement(By.id("query-table_next"));
if (!nextBtn.getAttribute("class").contains("disabled")) {
nextBtn.click();
Thread.sleep(1000);
} else {
flag = false;
System.out.println("In the last page");
}
}