相关疑难解决方法(0)

使用Python在Selenium WebDriver中获取WebElement的HTML源代码

我正在使用Python绑定来运行Selenium WebDriver.

from selenium import webdriver
wd = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)

我知道我可以抓住这样的一个元素......

elem = wd.find_element_by_css_selector('#my-id')
Run Code Online (Sandbox Code Playgroud)

而且我知道我可以获得完整的页面来源...

wd.page_source
Run Code Online (Sandbox Code Playgroud)

但无论如何要获得"元素来源"?

elem.source   # <-- returns the HTML as a string
Run Code Online (Sandbox Code Playgroud)

用于Python的selenium webdriver文档基本上不存在,我在代码中看不到任何似乎启用该功能的内容.

有关访问元素(及其子元素)的HTML的最佳方法的任何想法?

python selenium automated-tests webdriver selenium-webdriver

434
推荐指数
7
解决办法
38万
查看次数