Get all child elements

前端 未结 4 374
太阳男子
太阳男子 2020-12-07 13:55

In Selenium with Python is it possible to get all the children of a WebElement as a list?

4条回答
  •  生来不讨喜
    2020-12-07 14:52

    Here is a code to get the child elements (In java):

    String childTag = childElement.getTagName();
    if(childTag.equals("html")) 
    {
        return "/html[1]"+current;
    }
    WebElement parentElement = childElement.findElement(By.xpath("..")); 
    List childrenElements = parentElement.findElements(By.xpath("*"));
    int count = 0;
    for(int i=0;i

提交回复
热议问题