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

前端 未结 4 1702
自闭症患者
自闭症患者 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:08

    Another option If you are basing your requirements strictly on the need to use Selenium, you might be able to do something like this using WebElements and getting the size of the returned list:

    List myListToCheck=currentDriver.findElements(By.xpath("somePath"));
    if(myListToCheck.size()>0){
    //do this
    }else{
    //do something else
    }
    

    Or just simply returning the size of the returned list; if that's all you really want to get from it...

    int mySize=myListToCheck.size()
    

    I believe once you have an established WebElements list, you can also use iterators to go over that list. Helpful, I dunno... just providing another way to get to the same end-game.

提交回复
热议问题