【问题标题】:C#: Selenium getting ::before pseudo selector dataC#:Selenium 获取 ::before 伪选择器数据
【发布时间】:2016-11-21 11:44:15
【问题描述】:

我在接收伪选择器数据时遇到了一些问题。

driver.FindElement(By.CssSelector(selector));

我的选择器字符串本质上是button:nth-child(2),它工作正常, 但我还需要获取伪数据和button:nth-child(2)::before 不是很有效,它只是保持为空。

我的语法不正确还是我应该使用其他方法或类似的方法?

【问题讨论】:

    标签: c# css selenium css-selectors


    【解决方案1】:

    Selenium API 不支持伪元素,但是你可以通过一段 JavaScript 获取当前样式的属性:

    var elem = driver.FindElement(By.CssSelector(...));
    
    var pseudo_content = driver.ExecuteScript(
        "return window.getComputedStyle(arguments[0],':before').getPropertyValue('content');"
        , elem);
    

    【讨论】:

      猜你喜欢
      • 2017-06-07
      • 2020-10-21
      • 2021-09-03
      • 2017-07-31
      • 2022-01-12
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多