如何从Capybara / Poltergeist中的另一帧内切换到帧?(How to switch to a frame from within another frame in Capybara/

编程入门 行业动态 更新时间:2024-10-28 08:29:43
如何从Capybara / Poltergeist中的另一帧内切换到帧?(How to switch to a frame from within another frame in Capybara/Poltergeist?)

我是Ruby on Rails的新手,我正在开发一个包含两个框架的目录网站:第一个包含产品系列,第二个框架在第一帧上单击时动态显示这些系列中的机器列表。 这是因为表单目标是该帧的名称:

我已经检查了这个答案,但有一个重要区别:我想通过工作“within_frame('families_frame')”迭代地点击第一帧中的产品系列链接,并获取第二帧中的机器列表。 然而,“switch_to_frame”和类似的解决方案不起作用,我得到以下错误: switch_to_window不应该从within , within_frame '或within_window的'块中调用。 (水豚:: ScopeError)

因为我的迭代器是从“within_frame”运行的。 如何切换到生成的帧,到达内容然后切换回工作帧? HTML结构是:

<HTML> <FRAME NAME="families_frame" SRC=".../productfamily.jsp"> <FRAME NAME="machines_frame" SRC=".../blank.jsp"> </HTML>

万分感谢。

I'm new to Ruby on Rails and I was working on a catalog website which consists of two frames: the first one contains product families and the second one dynamically shows the list of machines within those families as you click them on the first frame. This happens since form target is that frame's name:

I have already inspected this answer but there is an important difference: I want to iteratively click through the product family links in the first frame by working "within_frame('families_frame')" and get the list of machines in the second frame. However "switch_to_frame" and similar solutions do not work and I get the following error: switch_to_window is not supposed to be invoked from within's, within_frame's' or within_window's' block. (Capybara::ScopeError)

Because my iterator runs from "within_frame". How can I switch to the resulting frame, reach the content and then switch back to the working frame? The HTML structure is:

<HTML> <FRAME NAME="families_frame" SRC=".../productfamily.jsp"> <FRAME NAME="machines_frame" SRC=".../blank.jsp"> </HTML>

Thank you a lot.

最满意答案

使用您发布的html结构,您需要在within_frame之外迭代,所以这样的事情

families = [] within_frame 'families_frame' do families = page.all('the selector for the items to iterate on') end families.each do |family| within_frame 'families_frame' do family.click end within_frame 'machines_frame' do # whatever you need to do in the machines frame end end

注意:这只有在系列框架没有更新的情况下才有效 - 如果您需要保留索引位置并在每次进入families_frame时查询它而不是能够遍历结果选择器或你最终会得到过时的元素引用

With the html structure you've posted you need to iterate outside your within_frame so something like this

families = [] within_frame 'families_frame' do families = page.all('the selector for the items to iterate on') end families.each do |family| within_frame 'families_frame' do family.click end within_frame 'machines_frame' do # whatever you need to do in the machines frame end end

Note: this will only work if the families frame isn't being updated too -- if it is you'll need to keep an index position and query for it each time you go into the families_frame rather than being able to iterate through the result of the selector or you'll end up with stale element references

更多推荐

本文发布于:2023-07-28 01:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1298339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:切换到   Poltergeist   Capybara   switch   frame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!