Reputation: 441
The case is the following: there are n panels on a page. Iterate through each panel: click on a specific element, then find the text of its child element which appears only after a click.
I can use methods like .has_css?, but that does not help me here.
Obviously it would be helpful to use find here, but it does not work on Capybara::Node::Element
page.all(:css, panelCss).each do |panel|
counter+=1
if panel.has_css?(elemCss)
Actions.c 'Yay! Found #'+counter.to_s
res = panel.find(:css, elemCss).text #**should be replaced**
end
end
As far as I remember, I have done the same thing in past by combining capybara and jquery, but could not find the decision yet. Brief googling also did not help.
P.S. Of course, I can iterate directly through clickable elements, make a click and then get the text of a child element instead of iterating through their parent panels, but there are 2 reasons:
Upvotes: 2
Views: 2196
Reputation: 49870
From your description it should be something like
page.all(:css, panelCss).each do |panel|
if panel.has_css?(elemToClickCss, wait: false) # assuming panels aren't dynamically loaded
c = panel.find(:css, elemToClickCss)
c.click
res = c.find(:css, clickedObjectsChildCss).text
end
end
Upvotes: 2