Get all immediate children and nothing deeper

后端 未结 4 1501
别跟我提以往
别跟我提以往 2021-02-03 21:20
WebElement body = browser.findElement(By.xpath(\"//body\"));

body.findElement(By.xpath(\"\")); // I want to get all child elements 
                                // i         


        
相关标签:
4条回答
  • 2021-02-03 21:24

    ("*") gives all the child elements of the context node. So use:

    body.findElement(By.xpath("*"));
    
    0 讨论(0)
  • 2021-02-03 21:28
    /html/body/*
    

    Will select only immediate children elements of body.

    Do remember that if you copy all these selected nodes, you also copy their content. So, if you do copy-of, table will also be produced to the resulting document.

    Also, I would recommend to read at least XPath basics, you ask too many similar questions.

    0 讨论(0)
  • 2021-02-03 21:29

    The child instead of descendant may helps someone.

    0 讨论(0)
  • 2021-02-03 21:32

    Here's another way to get the direct children of an element:

    element.findElement(By.xpath("./*"));
    
    0 讨论(0)
提交回复
热议问题