How Selenium's ByChained class really works?

后端 未结 3 993
一生所求
一生所求 2020-12-30 08:10

I am very confused with what the documentation for ByChained class mentions. It says:

Mechanism used to locate elements within a docu

3条回答
  •  既然无缘
    2020-12-30 08:27

    Your request would be satisfied by something that could be called ByAny which would return elements that match any of the passed By arguments. There's no such class AFAIK.

    However, ByChained works differently. It finds the elements that are matched by the first argument, then searches their descendants using the second argument etc. So, if you had HTMl like this:

    
        
            

    and you wanted to find the class=personName element under id=details, you could either use a CSS selector, an XPath expression, or the

    new ByChained(By.id("details"), By.className("personName"))
    

    Note that there also is a ByAll class that searches for elements matched by all of the By arguments passed.

提交回复
热议问题