且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Selenium - WebDriver.findElement() 和 WebElement.findElement() 之间的区别

更新时间:2022-06-26 05:49:08

WebElement.findElement() 将使用元素作为搜索选择器的范围.这意味着它通常用于搜索子元素.

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() 将使用驱动程序(即整个页面)来搜索给定的选择器.

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

因此,对于您的实例(我们需要更多信息来更准确地找出它),您的选择器很可能不匹配给定 WebElement 的任何子元素,但是当 driver 试图在整个页面(不包括 iframe)中搜索它时,它可以找到它.

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.