2
$\begingroup$

I'm currently trying to open, manipulate, and close a "new" browser window(by "new" I mean there's already a existing browser window) in a single google chrome session in WebUnit` Package, Theoretically it's possible but I really don't know how to directly interact with Google Chrome driver.

Can anyone help? Thanks!

$\endgroup$
  • $\begingroup$ I'm not quite sure whether this is a valid question for this site cause it may need the package creator's help, but fortunately the creator @Arnoud Buzing is on this site :) $\endgroup$ – Wjx Jun 11 '17 at 9:47
2
$\begingroup$

Simple example (note the package installs and executes it's own copies of chromedriver) https://github.com/arnoudbuzing?tab=repositories :

 Needs["WebUnit`"]
 InstallWebUnit["ChromeDriver"]
 StartWebSession[]
 OpenWebPage["http://mathematica.stackexchange.com"]
 ClickElement[Id["nav-users"]]
 pagePNG = CaptureWebPage[]
 pageHTML = 
  JavascriptExecute[
  "return document.getElementsByTagName('html')[0].innerHTML;"];
 StringTake[pageHTML, 50]
 JavascriptExecute["alert('hi');"]
 StopWebSession[]
$\endgroup$
  • $\begingroup$ Oh, sorry I didn't express myself clear enough, but I mean open a new tab on the same browser, e.g. Open another tab Google.com after MSE, in the final state, there shall be two tabs opening on the same browser. $\endgroup$ – Wjx Jun 12 '17 at 0:46
  • 1
    $\begingroup$ I think you can use javascript to open a new tab, see url below. However, I don't think you can get around the creation of a new chrome instance when you start chromedrive, that appears to be the way it works. Makes sense as it need top down control. You can still interact with this instance of chrome in parallel to commands sent from chromedriver. Good hunting. stackoverflow.com/questions/15818892/… $\endgroup$ – Dave Jun 13 '17 at 22:11
  • $\begingroup$ A new chrome instance could be created by evaluating StartWebSession[] again I suppose? $\endgroup$ – Wjx Jun 14 '17 at 2:45
  • 1
    $\begingroup$ Your suggestion really helped! It leads me to a correct path~ JavascriptExecute[ "window.open('" <>html<> "', '_blank', 'toolbar=yes, location=yes, status=yes, menubar=yes, \ scrollbars=yes');"] works! $\endgroup$ – Wjx Jun 14 '17 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.