grabAttributeFrom() 方法不返回属性值
grabAttributeFrom() method not returning the attribute value
我正在尝试使用 I.grabAttributeFrom()
方法获取元素的属性值,但我总是得到 undefined 而不是属性值。我的密码是
Scenario('Smoketest', async (I) => {
const columnIndex = await I.grabAttributeFrom('//th[text()="Status"]', 'aria-colindex');
});
元素就是这样
<th aria-colindex = "2">
"Status"
<span> ... </span>
</th>
我在 codeceptjs 中使用 testcafe。
我也无法让它工作,所以我写了一个量角器帮助程序来获取文本属性:
/**
* 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");
}
我正在尝试使用 I.grabAttributeFrom()
方法获取元素的属性值,但我总是得到 undefined 而不是属性值。我的密码是
Scenario('Smoketest', async (I) => {
const columnIndex = await I.grabAttributeFrom('//th[text()="Status"]', 'aria-colindex');
});
元素就是这样
<th aria-colindex = "2">
"Status"
<span> ... </span>
</th>
我在 codeceptjs 中使用 testcafe。
我也无法让它工作,所以我写了一个量角器帮助程序来获取文本属性:
/**
* 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");
}