0

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.

Community
  • 1
  • 1
Riman
  • 65
  • 1
  • 4
  • If this really is two sibling frames with one affecting the other (a strange page setup) you can't go from one frame to the other without returning to the parent first. From a given frame you can only go to it's parent or it's child frames. Show an example of the html structure for a more complete answer. – Thomas Walpole Jul 23 '16 at 21:14
  • Thank you for your response, I have added the actual html structure but omitted the part. – Riman Jul 23 '16 at 23:26

1 Answers1

0

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

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Could you please elaborate on the method you mentioned in the note? Families frame isn't updated but what i need is to click on a family, then go to machines frame and parse the table, then go back to families, click the next one etc. – Riman Jul 24 '16 at 02:02
  • @RavshanKh Thats exactly what the code I posted will do - it starts by going to the families frame and parsing all the family elements (I don't know what the selector for those would be) - then it returns to the parent frame - and for each element now in families it swaps to the families frame, clicks the family element, returns to the parent, swaps to the machines frame - you do whatever you need to in that frame, swaps back to the parent, and iterates to the next family – Thomas Walpole Jul 24 '16 at 02:17
  • Thank you very much! It worked like magic! I almost lost hope until this! – Riman Jul 24 '16 at 02:39