C#:硒在伪选择器数据之前获取:: [英] C#: Selenium getting ::before pseudo selector data
问题描述
我在接收伪选择器数据时遇到麻烦.
I'm having some trouble receiving pseudo selector data.
driver.FindElement(By.CssSelector(selector));
我的选择器字符串本质上是button:nth-child(2)
,可以正常工作,
但我还需要获取伪数据和button:nth-child(2)::before
不是很有效,它只是保持为空.
My selector string is essentially button:nth-child(2)
which works fine,
but I also need to get the pseudo data as well and button:nth-child(2)::before
isn't quite working, it just remains null.
我的语法不正确吗?还是应该使用其他方法或类似的方法?
Is my syntax incorrect or should I be using a different method or something along those lines?
推荐答案
Selenium API不支持伪元素,但是您可以使用一段JavaScript来获取当前样式的属性:
The Selenium API doesn't support pseudo elements, but you can get the properties of the current style with a piece of JavaScript:
var elem = driver.FindElement(By.CssSelector(...));
var pseudo_content = driver.ExecuteScript(
"return window.getComputedStyle(arguments[0],':before').getPropertyValue('content');"
, elem);
这篇关于C#:硒在伪选择器数据之前获取::的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!