gpt4 book ai didi

html - 从 html 元素中获取 data-id

转载 作者:太空宇宙 更新时间:2023-11-04 15:59:25 24 4
gpt4 key购买 nike

我正在尝试提取 data-id 的内容。例如:

<div data-id= "43434"></div>

如何获取 43434 的值?我想访问数据的内容。

最佳答案

如我所见,您想在 TestCafe 测试中获取此值。

如果是这样,您可以使用 Selector.getAttribute()方法。

const element   = Selector('your-div-selector');
const attrValue = await element.getAttribute('data-id');

// or if you need to use it in an assertion
await t.expect(element.getAttribute('data-id')).eql('43434');

关于html - 从 html 元素中获取 data-id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42764079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com