How to create element's Xpath using different search ( cssSelector / tag / ClassName )

后端 未结 1 416
灰色年华
灰色年华 2021-01-27 17:09

I would like to find an element using a differect cssSelector / tag / ClassName amd them get it\'s xpath value ( to be more specific, I have a website where when a day changes,

相关标签:
1条回答
  • 2021-01-27 17:24

    You can find the index by locating all the <td> elements in the first row and check wich one has the index

    List<WebElement> columns = driver.findElements(By.xpath("//tr[td[@class='active']]/td")); # just an example, can be any other locator
    int index = 0;
    for (int i = 0 ; i < columns.getSize() ; i++) {
        String attribute = columns.get(i).getAttribute("class")
        if (attribute != null && attribute.equals("active")) {
            index = i + 1;
        }
    }
    
    0 讨论(0)
提交回复
热议问题