Locating child nodes of WebElements in selenium

前端 未结 5 2034
谎友^
谎友^ 2020-11-29 03:13

I am using selenium to test my web application and I can successfully find tags using By.xpath. However now and then I need to find child nodes within that node

5条回答
  •  攒了一身酷
    2020-11-29 03:34

    According to JavaDocs, you can do this:

    WebElement input = divA.findElement(By.xpath(".//input"));
    

    How can I ask in xpath for "the div-tag that contains a span with the text 'hello world'"?

    WebElement elem = driver.findElement(By.xpath("//div[span[text()='hello world']]"));
    

    The XPath spec is a suprisingly good read on this.

提交回复
热议问题