watir 的 browser.text.include 吗?计算不可见 div 内的文本?如果是这样,如何仅搜索可见文本?

发布于 2024-08-30 20:35:52 字数 203 浏览 1 评论 0原文

watir 的 browser.text.include 吗?计算不可见 div 内的文本?如果是这样,如何仅搜索可见文本?

我从一开始就将所有说明放入 html 中,并使用 jQuery 隐藏和取消隐藏相关部分。

如何使用 watir 的 waiter 只等待可见的文本?

我的问题是,即使在我使某个文本可见之前,服务员也总是返回 true。

Does watir's browser.text.include? count text inside invisible divs? If so, how to search only for visible text?

I put all the instructions into the html from the beginning and use jQuery to hide and unhide the relevant parts.

How can I use watir's waiter to wait for only text that is visible?

My problem is, that the waiter always returns true, even before I have made visible a certain text.

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

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

发布评论

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

评论(3

望喜 2024-09-06 20:35:52

不要使用 Watir 的文本方法。它非常快速和肮脏,并且有很多疑虑,许多甚至与可见文本的问题无关。 Solid Watir 测试开发人员将避免它。我自己几乎从不使用它,只有当我做一些非常快速和肮脏的事情时才使用它。此外,不同的浏览器的实现方式也不同。

相反,您应该根据其所在的实际元素来访问您关心的文本。您应该引用 div 或其他内容。

Don't use Watir's text method. It is very quick and dirty, and has lots of misgivings, many not even related to this issue about visible text. Solid Watir test developers will avoid it. I almost never use it myself, and only when I am doing something extremely quick and dirty. Also, it is implemented differently with different browsers.

Instead you should access the text you care about in terms of the actual element that it is in. You should reference the div or whatever.

送你一个梦 2024-09-06 20:35:52

有什么问题

text_from_all_my_visible_divs = br.div(:id, 'divs I care about').divs.select do |div|
  text_i_care_about(div) && div.visible?
end

def text_i_care_about(div)
  div.text =~ /regexp/
end

.visible 吗?在单元测试中,这是官方的,不要害怕:)

艾伦

What's wrong with:

text_from_all_my_visible_divs = br.div(:id, 'divs I care about').divs.select do |div|
  text_i_care_about(div) && div.visible?
end

def text_i_care_about(div)
  div.text =~ /regexp/
end

.visible? is in the unit tests, it's official, don't be scared of it :)

Alan

眸中客 2024-09-06 20:35:52

include? 可以看到所有文本,而不仅仅是可见文本。有关详细信息,请参阅 WTR-433 票证。

Element#visible? 方法不受官方支持(如据我所知)。

你想做什么?如果页面上有很多文本,并且只想显示其中的一部分,则可以将文本放在几个 div 中,然后查看 div 是否可见。

include? sees all text, not just visible text. See WTR-433 ticket for details.

There is Element#visible? method that is not officially supported (as far as I know).

What are you trying to do? If you have a lot of text on the page, and want to show only some of it, you could put the text in a few divs and then see if the div is visible.

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