java 搜索Selenium后显示表的其余部分

dbf7pr2w  于 2023-02-07  发布在  Java
关注(0)|答案(1)|浏览(85)

我需要用Selenium进行搜索并显示结果,实际上,我在Selenium中有一个程序,它可以显示一个表,并在文本字段中输入搜索词,当搜索词自动写入时,将包含这些词的列制成表格。
这是我程序里的一段代码

private static String searchName = "//*[@id=\"searchName\"]";
private static String tableExist = "//table[@role='table']/tbody/tr";

//return if exist elements in the table
public static Boolean elementExistsInTheTableCustomer() {
    return (driver.findElements(By.xpath(tableExist)).size() > 0);
}
// here i put the text search
public static void enterSearchName(String nameSearchTxt) {
    driver.findElement(By.xpath(searchName)).sendKeys(nameSearchTxt);
}
// this function to put 2 char to search in the table
public static void searchStringName() {
    String strSearch = RandomStringUtils.randomAlphabetic(2);
    System.out.println("The String search : " + strSearch);
    Customer.enterSearchName(strSearch);
}
public static WebElement displayElementTables() {
    WebElement list =  webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(tableExist)));        
    return list;
} 

//here the test of element after and before the search name
@Test
public void GIVEN_Customers_On_Database() throws InterruptedException {
    Customer.clickCustomers();
    Thread.sleep(3000);
    if (Customer.elementExistsInTheTableCustomer()) {
        System.out.println("\t===============================");
        for (WebElement detail : Customer.displayElementTables()) {
            System.out.println("\t The elements in the table : " + detail.getText());
        }
        System.out.println("\t===============================");            
    }
    Customer.searchStringName();
    // here to display if i have elements or no 
    for (WebElement detail : Customer.displayElementTables()) {
            System.out.println("\t The elements in the table : " + detail.getText());
        }
}

在最后一部分,我将检查他是否有任何行要发布。**displayElementTables()**函数,我可以在其中接收搜索结果。我是否有项目,并将结果放在一个变量中显示。

3yhwsihp

3yhwsihp1#

public static List<WebElement> displayElementTables() {
    List<WebElement> list =  webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(tableExist)));        
    return list;
}

相关问题