【问题标题】:How to get pseudo elements in WebdriverIO+AppiumWebdriverIO+Appium中如何获取伪元素
【发布时间】:2020-04-02 18:25:13
【问题描述】:

我想在使用 WDIO 和 Appium 为 Android 混合应用程序进行的测试中从伪元素 (::before) 的 CSS 中获取一个值 (content),因为设计人员已经存储了当前的响应式设计在那里陈述。所以我的测试会知道预期的布局(元素)。

相关问题的多个答案(123)表明使用.getComputedStyle() 可能是唯一的解决方案。但这在我的测试中似乎不起作用。如果我使用document.defaultView.getComputedStyle(...),则错误为window is not defined for window.getComputedStyle(...)document is not defined。选择器本身也无法处理 seems 的伪元素。

我的许多尝试之一的示例:

document.defaultView.getComputedStyle($('body'),'::before').getPropertyValue('content')

问题:我需要以某种方式将windowdocument 导入到我的测试中吗?有没有其他方法可以从测试中获取windowdocument

最终:如何获得混合 Android 应用程序的 <body>::beforecontent 值?

【问题讨论】:

    标签: appium pseudo-element webdriver-io appium-android wdio-jasmine


    【解决方案1】:

    感谢 Jeremy Schneider (@YmerejRedienhcs) 和 Erwin Heitzman (@erwinheitzman) 的帮助!

    一种解决方案是使用execute 函数:

    let contentMode = browser.execute(() => {
      let style = document.defaultView.getComputedStyle(document.querySelector('body'),'::before');
      return style.getPropertyValue('content')
    });
    

    另外也许也可以使用getHTML 来做一些事情。

    【讨论】:

      猜你喜欢
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 2017-06-19
      • 2023-04-02
      • 2016-01-19
      • 2016-05-11
      相关资源
      最近更新 更多