是否可以使用 watir 单击非链接的文本

发布于 11-16 23:52 字数 330 浏览 5 评论 0 原文

我在 Firefox 浏览器中使用 watir

我正在寻找一种方法来单击不是链接的文本。我已经验证该文本存在于网站上,使用

b.text.include? "Tasks"

我尝试了几种不同的方法来单击此文本,但所有方法均不成功,到目前为止我已经尝试过

b.link(:text, "Tasks").click
b.text.click "Tasks"
b.text(:text, "Tasks").click

是否有一种方法可以使用 watir 单击此文本?任何帮助将非常感激

i am using watir in the firefox browser

I am looking for a way to click on text that is not a link. I have verified that the text exists on the website using

b.text.include? "Tasks"

I've tried several different ways to click on this text, but all have been unsuccessful, thus far i have tried

b.link(:text, "Tasks").click
b.text.click "Tasks"
b.text(:text, "Tasks").click

is there a way to click on this text using watir? any help would be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狂之美人 2024-11-23 23:52:04

如果点击这个不是链接的文本会导致某些事情发生,那么很可能有一个容器元素封装了文本,该文本被“连接”以在特定事件时执行某些特定的 JavaScript (如 onMouseDown 或 onClick)被检测到。根据开发人员设计页面的方式,可以使用大量元素类型(span、div、表格单元格等)。

由于可以嵌套多个容器(就像俄罗斯娃娃的极客版本),因此了解或弄清楚单击哪个容器将触发客户端代码非常重要。为此,您需要查看页面的 HTML 或使用开发人员工具(所有现代浏览器都有它们)来检查“可点击”文本附近的 DOM

。一般建议,我们需要查看页面该部分的 HTML,以便能够判断这是什么类型的元素,并建议正确的(如何、什么) 创建所需的值和元素类型单击元素或触发所需事件的代码行。

直到您可以提供额外的详细信息(编辑您的问题以添加信息)之前,您的问题以及答案都将受到 GIGO 综合症

If clicking on this text that is not a link causes something to happen, then it is likely that there is an container element that encapsulates the text which is 'wired' to execute some specific javascript when a particular event (like onMouseDown or onClick) is detected. A large number of element types are possible (span, div, table cell, just to name a few) depending on how the developer designed the page.

Since multiple containers can be nested (ala a geek version of Russian Dolls) it's important to know or figure out which one will trigger the client side code when it is clicked. To do this you need to look at the HTML for the page or use a developer tool (all modern browsers have them) to examine the DOM in the vicinity of the text that is 'clickable'

To give you a better answer that is anything but general advice, We Need To See The HTML for that part of the page in order to be able to tell what kind of element this is, and suggest the proper (how, what) values and element type that would be needed in order to create the line of code that would click on the element, or fire the needed event.

Until you can provide that additional detail (EDIT your question to add the information to it) your question and hence the answers as well, will all suffer from GIGO syndrome

2024-11-23 23:52:04

如果您尝试单击的文本包含在段落或跨度标签中,是否可以通过这种方式选择它?如果包装标签具有标识符,您还可以使用 :id 选择器。希望这有效。

我不知道您的用例,但如果文本可能是一个链接,您可以使用"="">event.preventDefault 以防止其执行任何操作。

If the text you're trying to click is contained in a paragraph or span tag, could possibly select it this way? You could also use the :id selector if the wrapping tag had an identifier. Hopefully that works.

I don't know your use-case, but if the text could be a link, you could use event.preventDefault on the click event to keep it from doing anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文