【问题标题】:Compare value in table by iterating table and select checkbox in front of that particular value通过迭代表比较表中的值并选择该特定值前面的复选框
【发布时间】:2020-10-22 17:38:34
【问题描述】:

以下是我的代码,它在执行时未显示任何错误,但未单击复选框。 列出列中的所有 Web 元素并获取所需的标题。

public void reviewProcessECL() {

    //to catch all web elements into list
    List<WebElement> myList=driver.findElements(By.xpath("//table/tbody/tr/td[5]"));

    //myList contains all the web elements
    //if you want to get all elements text into array list
    List<String> all_elements_text=new ArrayList<>();

    for(int i=0; i<myList.size(); i++) {

        all_elements_text.add(myList.get(i).getText());
        String id= myList.get(i).getText();

        if(id.contains(tdata.getProperty("Letter_Subject"))) {
            i++;    
            driver.findElement(By.xpath("//table/tbody/tr["+i+"]/td[11]")).click();
            driver.findElement(By.xpath("//table/tbody/tr["+i+"]/td[11]//div[@class='dropBox']//a[contains(text(),'Add Works')]")).click();

        }
    }
}

【问题讨论】:

  • 能否分享一下的HTML源码?

标签: java selenium gradle selenium-chromedriver testng


【解决方案1】:

试试这样的,

public void clickOnDropDown(String dropDownValue) {
        driver.findElement(By.xpath("yourXpath")).click();// click the dropdown

        List<WebElement> stroreValueFromDropDown = driver.findElements(By.xpath("yourXpath"));// store dropdown values

        for (WebElement list : stroreValueFromDropDown) { //iterate through the dropdown
            String listValue = list.getText();// get text
            if (listValue.contains(dropDownValue)) {// compare dropdown and expected text
                list.click();// click when expected value is found 
                break;
            }

        }

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    相关资源
    最近更新 更多