Count the number of elements are matching with for the given xpath expression

前端 未结 4 1701
自闭症患者
自闭症患者 2021-02-14 20:35

How to count the number of elements are matching with for the given xpath expression

xpath: driver.findElement(By.xpath(\"//div[contains(@id,\'richedittext_insta         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 21:16

    Not working in Selenium, which only allows to return nodes from XPath, not primitives like the number returned by count(...). Kept for reference and is valid for most other tools offering a more complete XPath API.

    You should only return least possible amount of data from the query. count(//div[contains(@id,'richedittext_instance')]) counts the number of results within XPath and thus is faster as all the elements do not have to be passed from the XPath engine to Selenium.

    I can't help you with how to fetch this as n int out of selenium, but this should be easy stuff.

提交回复
热议问题