admin管理员组文章数量:1406926
is it possible to get the target on click? for example, I have the following code:
await page.mouse.click(200, 200)
and in this position I have an input, is it possible to get the target in this clicked position and find out that there is a input there?
is it possible to get the target on click? for example, I have the following code:
await page.mouse.click(200, 200)
and in this position I have an input, is it possible to get the target in this clicked position and find out that there is a input there?
Share Improve this question asked Jun 5, 2020 at 15:21 Nir BerkoNir Berko 1,4364 gold badges16 silver badges36 bronze badges 3- Is there any reason you rather click the position instead of the input itself? – innis Commented Jun 5, 2020 at 15:46
- @innis just for learning :) – Nir Berko Commented Jun 5, 2020 at 15:51
- I can't think in any way to do this rather than set an variable and the set an event listener for each one of your inputs and then define the previously declared variable with the value you want to set when you click. – innis Commented Jun 5, 2020 at 22:54
1 Answer
Reset to default 4You can pass the coordinates to the document.elementFromPoint
method (MDN docs). Since this method is in the web page context, we will use page.evaluate
in the Playwright API.
await page.evaluate(([x, y]) => {
const element = document.elementFromPoint(x, y);
return element instanceof HTMLInputElement;
}, [200, 200])
The x, y values in the page.mouse.click
are relative to the top-left corner of the viewport, which is what the elementFromPoint
API expects.
本文标签: javascriptplaywright get click targetStack Overflow
版权声明:本文标题:javascript - playwright get click target - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744381148a2603511.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论