如何使用硒python获取伪元素的css值? [英] How to get css value of pseudo element with selenium python?
本文介绍了如何使用硒python获取伪元素的css值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有html o页面:
I have html o page:
<div id="foo" class="bar" title>
::before
</div>
在选择 :: before
的Chrome或Firefox上,我可以在样式"选项卡上看到CSS:
With Chrome or Firefox on selection ::before
I can see css on Styles tab:
.SomeTitle .bar::before{
content: "required_value"
}
选择< div id ="foo" class ="bar" title>
后,它以 Pseudo :: before元素
呈现.我确实试图获得 content
的价值:
After selection <div id="foo" class="bar" title>
it presented in Pseudo ::before element
. I did try to get value of content
:
browser = webdriver.Firefox()
browser.get(my_url)
my_element = browser.find_element_by_xpath("//*[@id='foo']")
my_elemet.value_of_css_property("content")
但是它不会返回任何内容.如何获得 content
的价值?
But it does returns none. How can I get value of content
?
推荐答案
好像我找到了解决方案.这不是纯硒,但确实可以.
Looks like I did find solution. This is not pure selenium but it does works.
browser.execute_script("return window.getComputedStyle(document.querySelector('.SomeTitle .bar'),':before').getPropertyValue('content')")
希望这对某人有帮助.
这篇关于如何使用硒python获取伪元素的css值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文