问题
The challenge I'm tasked with is to run headless (most of the time) but have the ability to launch the current state of the headless browser in the default browser on the machine.
By headless I mean no open browser windows. So I'm running PhantomJS in conjunction with waitr-webdriver.
In the headless state I am completing a multi-page form. At the end of the form I need to be able to launch that page/session with current state in my native browser. How can this be accomplished?
Imagine this scenario:
#1 open_page (Headless)
@browser = Watir::Browser.new :phantomjs
@browser.goto "www.somewebsite.com"
#2 fill in form (Headless)
field = @browser.text_field(:id => 'field')
field.set 'somevalue' if field.exists?
#3 click to next page (Headless)
button = @browser.button(:id => 'submitButton').click
#4 fill in form (Headless)
field = @browser.text_field(:id => 'field')
field.set 'somevalue' if field.exists?
#5 click to next page (Headless)
button = @browser.button(:id => 'submitButton').click
#6 results page (Open this page in my native browser)
@browser.open # {Pseudo-code}
#6
Is not working. This is where I need your advice/recommendation.
回答1:
You would need to open a different browesr (@browser2) and then load the URL. Keep in mind this won't have the exact same environment as the headless version.
来源:https://stackoverflow.com/questions/23593396/truly-headless-web-browser-with-non-headless-abilites