使用量角器获取伪元素的值

getting the value of a pseudo-element with protractor

本文关键字:元素 获取 量角器      更新时间:2023-09-26

我想验证伪元素的文本内容。使用ptor.executeScript("window.getComputedStyle(jQuery('.my-class')[0], ':after').content").then(function(data){ console.log(arguments) // {'0':null} });返回

的承诺

我也尝试在期望中放弃它,但我想由于同样的原因而失败。

由于CSS声明无论如何都指向元素的一个属性,我应该尝试读取该属性吗?

>executeScript将等待您返回一个值 - 因此您需要执行以下操作:

ptor.executeScript("return window.getComputedStyle(jQuery('.my-class')[0], ':after').content")
    .then(function(data){ console.log(arguments)});

作为基于我们的好朋友朱莉(又名"量角器向导")的更新答案。

我没有可用的jQuery来获取我的pseduo元素,所以我这样做了......

describe('#swPopover Component', () => {
    it('should show the popover message when hovered', () => {
      browser.actions().mouseMove(objectsPage.popover).perform();
      browser.executeScript('return window.getComputedStyle(document.querySelector(".sw-popover"), ":after").content')
        .then(data => expect(data).toBe('"I am the popover text"'));
    });
  });