如何使用一段时间来扫描所有页面,以查找Ruby或Capybara的特定记录
有人告诉我,Capybara只有在页面上可见时才会找到它。 Ruby可以扫描所有页面寻找此唱片吗?
我尝试了下面的解决方案:但是根据我的朋友托马斯(Thomas)的帮助,只有在列表中可见的项目(如果是另一个分页)中,才能找到辣椒粉,Capybara找不到它
@ger_material_active = = 'automation_server_aluminio_active'+ rand(1..99).to_s 查找(“ TD”,文本:@ger_material_active).click
I've been told that capybara will only find it if it's visible on the page. Is it possible with ruby to scan all pages looking for this record?
I tried the solution below: But according to the help of my friend Thomas, Capybara can only be found if the item is visible in the list, if it is in another pagination, Capybara cannot find it
@ger_material_active = 'automation_Server_ALUMINIO_ACTIVE'+ rand(1..99).to_s
find("td", text: @ger_material_active).click
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以使用循环来完成所有分页响应,直到找到所需的文字为止。为此,您必须知道要单击该页面以移至结果的下一页,并且要么选择指示结果页面已完成的内容或设置了每个页面的等待时间足够长的时间加载
这是最简单的方法,但也将是最慢的方法,因为您需要设置
等待
值足够大以确保每次都加载下一组结果。检测指示结果已加载/加载的页面更改将更有效它的工作原理(出现/消失的元素,状态变化等)。除非您确保编写的代码单击“结果的下一页”,否则这也有可能创建一个无尽的循环结果。Yes you could use a loop to work through all the paginated responses until you find the text you're looking for. To do that you'd have to know what to click on the page to move to the next page of results, and either a selector for something that indicates a page of results has finished loading or set a long enough wait time for each page to load
This is the simplest approach but will also be the slowest since you're going to need to set the
wait
value large enough to ensure the next set of results have been loaded each time. It would be more efficient to detect page changes that indicate the results are loading/loaded instead of just waiting up to some amount of seconds for the element to appear, however telling you how to do that would require a lot more information about the page and how it works (what elements appear/disappear, state changes, etc). There's also the chance this could create an endless loop unless you make sure the code you write to click the button for the next page of results realizes it's on the last page and doesn't just continue to keep trying to click for a new page of results.