如何从元素中获取文本值?



get text元素有问题

<style id="main-style-inline-css" type="text/css">
body{--accent:141, 65, 48;--accent--tone:199, 111, 92; ...
</style>

已尝试,但返回空值:

theme_Colors = "//style[@id='main-style-inline-css']"
test = driver.find_element(By.XPATH, theme_Colors).text
driver.find_element(By.XPATH, theme_Colors).getAttribute("innerHTML");

尝试innerHTML代替文本作为内容,没有文本节点

对于python,函数为get_attribute(),则使用innerHTMLinnerText的属性

test = driver.find_element(By.XPATH, theme_Colors).get_attribute('innerText')

最新更新