我想在java中使用selenium对表进行分页

pepwfjgg  于 2022-12-18  发布在  Java
关注(0)|答案(1)|浏览(139)

我需要你的帮助,我想通过一个表分页和存储值,直到“下一步按钮”禁用。虽然存储值是不可行的,它的确定。但帮助我分页,我想点击按钮,它的下一步按钮,直到它没有被禁用。请帮助我。我在实习
Java代码:

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']

网址:

igetnqfo

igetnqfo1#

登录后,一旦您到达包含报告列表的表,请添加以下代码并尝试:

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");
    }
}

相关问题