有人向我解释一下这是如何工作的吗? [关闭]

问题描述 投票:0回答:0
public static void searchTextInsideViewGroupAndClick(List<WebElement> list, String word, String status) {
    StringBuffer result = new StringBuffer();
    List<String> text = new ArrayList<>();
    for (int x = 0; x <= list.size(); x++) {
        Pattern p = Pattern.compile("(?<=-> xpath:)(.*)(?=])");
        Matcher m = p.matcher(String.valueOf(list.get(x)));
        m.find();
        String el = m.group(0);
        Integer list2 = web().getWebDriver().findElements(By.xpath(el + "[" + (x + 1) + "]" + "(//span[text()=" + status + "])[2]"))
                .size();
        for (int y = 1; y <= list2; y++) {
            String txt = web().getWebDriver()
                    .findElements(By.xpath(el + "[" + (x + 1) + "]" + "(//span[text()=" + status + "])[2][" + y + "]"))
                    .iterator().next().getText();
            text.add(txt);
            result = text.stream().map(StringBuffer::new).reduce(new StringBuffer(""), StringBuffer::append);
        }
        if (!result.toString().contains(word)) {
            list.get(x).click();
        }
    }
}

我有一个元素列表,我想单击这些元素并使用文本(字符串状态)进行搜索,但这些元素是相同的并且没有 ID。 我想使用标签并滚动元素列表,然后单击带有我传递的文本的特定元素。

java selenium-webdriver web automation
© www.soinside.com 2019 - 2024. All rights reserved.