Selenium - Difference between WebDriver.findElement() and WebElement.findElement()

后端 未结 2 1068
孤独总比滥情好
孤独总比滥情好 2021-01-07 02:49

I was using WebElement.findElement(By.cssSelector(\'\')).click(); to find an element on a page , but it returned \"Unable to locate element\", But

相关标签:
2条回答
  • 2021-01-07 03:16

    WebElement.findElement() will use the element as the scope in which to search for your selector. This means it is generally used for searching for child elements.

    WebDriver.findElement() will use the driver (i.e the entire page) to search for your given selector.

    So for your instance specifically (and we'll need more information to figure it out more accurately) it's more than likely your selector doesn't match anything that is a child of your given WebElement, but when the driver tries to search for it in the entire page (excluding iframes), it can find it.

    0 讨论(0)
  • 2021-01-07 03:22

    WebDriver represents your browser and WebElement represents individual elements present on web page.for better understanding can u provide your code.

    0 讨论(0)
提交回复
热议问题