Find an element by text and get xpath - selenium webdriver junit

后端 未结 11 731
情深已故
情深已故 2020-12-03 04:17

I have a table with 9 rows and 6 columns in my webpage. I want to search for a text \"MakeGoodDisabled-Programwise_09_44_38_461(n)\" and get the xpath of the cell. I have us

11条回答
  •  隐瞒了意图╮
    2020-12-03 04:41

    Before iterating, use this class. Then, when you findXPATHIDFromWebElement

    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    
    public class XPATHDriverWrapper {
    Map xpathIDToWebElementMap = new LinkedHashMap();
    Map webElementToXPATHIDMap = new LinkedHashMap();
    public XPATHDriverWrapper(WebDriver driver){
        WebElement htmlElement = driver.findElement(By.xpath("/html"));
        iterateThroughChildren(htmlElement, "/html");
    }
    
    private void iterateThroughChildren(WebElement parentElement, String parentXPATH) {
        Map siblingCountMap = new LinkedHashMap();
    
        List childrenElements = parentElement.findElements(By.xpath(parentXPATH+"/*"));
        for(int i=0;i

    Another wrapper class to generate ids from Document is posted at: http://scottizu.wordpress.com/2014/05/12/generating-unique-ids-for-webelements-via-xpath/

提交回复
热议问题