英文:
Does WebElement class inherits from WebDriver class in Selenium Python?
问题
在代码的第二行,我使用了Webdriver
类的find_element_by_xpath()
方法与WebElement
对象,它运行正常。
这是如何实现的呢?在Selenium Python中,WebElement
类是否继承自WebDriver
类?
Selenium Python中的WebElement
类并没有继承自WebDriver
类。那么,我们如何能够在WebElement
对象中使用WebDriver
类的方法呢?
英文:
Sample code:
score_both_halves = driver.find_element_by_xpath('//label[@data-btn-radio="\'ScoreBothHalves\'"]')
score_both_halves.find_element_by_xpath()
In the second line of code I used a find_element_by_xpath()
method of Webdriver
class with WebElement
object and it works fine.
How is that possible? Is WebElement
class inherits from WebDriver
class in selenium python?
Isn't the WebElement class inherits from WebDriver class in selenium python? If not then how we can use methods of WebDriver class with WebElement object?
答案1
得分: 1
-
Remote WebDriver实现包含方法find_element()
-
用法:
element = driver.find_element(By.ID, 'foo')
-
返回类型:
WebElement
-
-
同样,Remote WebElement实现也包括方法find_element()
-
用法:
element = element.find_element(By.ID, 'foo')
-
返回类型:
WebElement
-
结论
因此,driver.find_element(By.ID, 'foo')
和 element.find_element(By.ID, 'foo')
都是有效的代码行。
英文:
As per the Selenium Python binding documentation:
-
The Remote WebDriver implementation contains the method find_element()
-
Usage:
element = driver.find_element(By.ID, 'foo')
-
Return type:
WebElement
-
-
Similarly The Remote WebElement implementation also includes the method find_element()
-
Usage:
element = element.find_element(By.ID, 'foo')
-
Return type:
WebElement
-
Conclusion
Hence driver.find_element(By.ID, 'foo')
and element.find_element(By.ID, 'foo')
both are valid lies of code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论