Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用form和target=";访问新页面_“空白”;通过水豚_Ruby On Rails_Capybara_Poltergeist - Fatal编程技术网

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
...