如何使用 Watir Webdriver 确定元素的坐标? [英] How to determine coordinates of an element with Watir Webdriver?

查看:23
本文介绍了如何使用 Watir Webdriver 确定元素的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.在解析页面时,会出现一个弹出窗口并阻止对 html 的访问.我试图点击弹出窗口,但它会将我重定向到一个新页面,我不知道如何到达弹出窗口的右上角区域来关闭它.我的问题是如何确定该元素的坐标?Stackoverflow 上提出的相关问题都没有帮助我找到解决方案,因此非常感谢您的帮助.

I have a problem. While parsing a page, a pop-up window appears and blocks access to html. I tried to click on the pop-up, but it re-directs me to a new page, and I have no clue how to get to the upper right area of the pop-up to close it. My question is how to determine the coordinates of that element? None of the related issues raised here at Stackoverflow helped me find a solutions, so assistance would be very much appreciated.

推荐答案

为什么需要实际坐标?鉴于它可以在不同的屏幕尺寸(响应式设计)上移动或产生不同的结果,这似乎是一个坏主意.你最好找到关闭按钮的类/id 并调用 browser.button(class: 'close').clickbrowser.link(class: 'close').click.

Why do you need the actual coordinates? That seems like a bad idea given it could move or have different results on different screen sizes (responsive designs). You'd be better off finding the class / id of the close button and calling browser.button(class: 'close').click or browser.link(class: 'close').click.

如果您需要帮助确定关闭按钮的类别,请打开浏览器并启用开发人员工具/控制台.他们现在都有一个检查器工具来选择元素并找到所有类和;id.

If you need help determining the class of the close button, open your browser and enable developer tools / console. They all have an inspector tool now to select the element and find all classes & ids.

万一没有类或 id,它可能有一个 data 属性,您可以使用它.

In the unlikely event there are no classes or ids it may have a data attribute you could work off.

这篇关于如何使用 Watir Webdriver 确定元素的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆