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

后端 未结 11 760
情深已故
情深已故 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:45

    Assuming you have an attribute on your element with the name "xpath" you could do the following:

    WebElement yourElement = driver.findElement(By.xpath("//td[contains(text(),'MakeGoodDisabled-Programwise_09_44_38_461(n)')]");
    String xpathAttributeValue = targetButton.getAttribute("xpath");
    

    Though by the sounds of it you are trying to achieve something else here you have not shared with us yet. Do you want selenium to create an xpath for you? It can't.

提交回复
热议问题