Ruby on rails 如何使用form和target=";访问新页面_“空白”;通过水豚
我正试图用水豚+恶灵来刮这一页Ruby on rails 如何使用form和target=";访问新页面_“空白”;通过水豚,ruby-on-rails,capybara,poltergeist,Ruby On Rails,Capybara,Poltergeist,我正试图用水豚+恶灵来刮这一页 <form action="/agency/advertiser/login" method="POST" role="form" target="_blank"> <input type="hidden" name="csrfToken" value="token"/> <input type="hidden" name="account_id" value="id"> <input ty
<form action="/agency/advertiser/login" method="POST" role="form" target="_blank">
<input type="hidden" name="csrfToken" value="token"/>
<input type="hidden" name="account_id" value="id">
<input type="submit" value="login" class="btn btn-warning">
</form>
但是,我无法访问单击后打开的新页面。我怎么做?你需要告诉水豚你想在新窗口工作。您可以通过获取新打开窗口的句柄,然后使用
in_window
或switch_window
来实现这一点
new_window = page.window_opened_by do
# perform whatever action causes the new window to open
page.find('form').click_button
end
page.within_window(new_window) do
# perform actions in the new window
end
# context returned to the original window
...
可能重复的
new_window = page.window_opened_by do
# perform whatever action causes the new window to open
page.find('form').click_button
end
page.within_window(new_window) do
# perform actions in the new window
end
# context returned to the original window
...