1

I am trying to get the attribute value of an element by using I.grabAttributeFrom() method but I always get undefined instead of the attribute value. My code is

Scenario('Smoketest', async (I) => {

const columnIndex = await I.grabAttributeFrom('//th[text()="Status"]', 'aria-colindex');

});

The element is like that

<th aria-colindex = "2">
"Status"
<span> ... </span>
</th>

And I am using testcafe in codeceptjs.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Rashed
  • 23
  • 5
  • I changed your selector to `th`, and it still does not work. I debugged the `testcafe` module, and it works as expected: the value `2` is returned. Probably the issue lies somewhere on the `codeceptjs` side. It makes sense to report it in their github repo. – Alex Kamaev Dec 03 '19 at 09:33
  • Thank you for confirming me that it is not a testcafe issue. I will check codeceptjs github repo. – Rashed Dec 04 '19 at 06:03
  • Fix was merged. Now waiting for next (2.4.0) release. Thanks for bug found – Evgeny Lukoyanov Dec 17 '19 at 09:38
  • Welcome. I will check the next release :) – Rashed Dec 18 '19 at 07:32

1 Answers1

2

I wasn't able to get it to work either, so I wrote a protractor helper that worked for me to grab text attributes:

  /**
   * Function to return the text content of all elements matching with the locator in an array
   * @param xpath object
   */
  async getElementsText(locator) {
    const driver = this.helpers.Protractor.browser;
    await driver.waitForAngular();
    // await console.log("Getting text for: " + locator.xpath);
    return driver.element.all(by.xpath(locator.xpath)).getAttribute("textContent");
  }