简体   繁体   中英

Can browser called from RSelenium run in the backround

I am working on a windows 7 machine. Is it possible to run remoteDriver()$open() from the RSelenium library and have the browser run in the background (ie not visible).

Thanks

Yes, that is possible. The default browser for RSelenium is Firefox. However, RSelenium even supports headless browsing using PhantomJS which is described in the respective vignette in detail.

In general, for leveraging PhanomJS under Windows 7 you just need to

  • download PhantomJS and add the folder path to the phantomjs.exe as an additional entry to the user or system PATH variable in the Environment Variable menu on your system (eg C:\\Program Files\\phantomjs-1.9.7-windows ) Note: phantomjs.exe itself is not part of the path specification.
  • replace the code snippets at the beginning and at the end of your code like described next

Default browsing:

checkForServer()
startServer()
remDrv <- remoteDriver()
remDrv$open()

...

remDrv$quit()
remDrv$closeServer()

Headless browsing:

pJS <- phantom()
remDrv <- remoteDriver(browserName = 'phantomjs')
remDrv$open()

...

remDrv$close()
pJS$stop()

Additional advice

Command line arguments and POODLE

Pay attention to the command line arguments which you can pass to phantom .

For instance, PhantomJS uses SSLv3 by default which is discouraged by every server since POODLE.

The workaround is to call phantom with --ssl-protocol=tlsv1 :

pJS <- phantom(extras = c('--ssl-protocol=tlsv1'))

Timing issues

One thing that often happens with PhantomJS is timing issues. Code that works with browsers such as Firefox and Chrome breaks with PhantomJS because PhantomJS is too fast.

You can solve this issue by placing Sys.sleep calls between the different remoteDriver calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM