1
$\begingroup$

A website opens properly with SystemOpen["url"] but fails to open properly with StartWebSession[] or WebExecute["OpenPage"-> "url string"]. Is there any way to use the $CurrentWebSession variable as the session variable in a WebExecute call in order to interact with the webpage opened by SystemOpen["url"]?

$\endgroup$
3
  • $\begingroup$ On my machine StartWebSession[] also fails with the Message: "Unable to start Chrome driver process" (despite that I have the latest version of Google Chrome installed). But StartWebSession["Firefox"] usually works (sometimes from the second trial - it seems that the first attempt to start Firefox takes too much time and doesn't fit some internal time constraint). $\endgroup$ Jan 21, 2022 at 10:35
  • $\begingroup$ Thanks. I spoke with tech support this morning. There's no way to do this so I'm setting up a interface to open the page which I'll then control with keyboard shortcuts. Cludgy but that's what there is unless the developers link SystemOpen and the resulting $CurrentWebSession to WebExecute. $\endgroup$
    – jcm
    Jan 21, 2022 at 18:19
  • 2
    $\begingroup$ I think SystemOpen and StartWebSession[] are two different approaches. SystemOpen opens a file and treats the input as a resource file path may it be a external url path or internal file path. StartWebSession creates the $CurrentWebSession object without specifying an url. The url is specified when you use WebExecute[session, "OpenPage"-> url] $\endgroup$
    – boobami
    Jan 21, 2022 at 20:11

3 Answers 3

1
$\begingroup$

I was having the same problem with StartWebSession[]. It would fail with the message: "invalid session id." Its not a perfect fix but I was able to get it to work by replacing the chromedriver in mathematica with an older version (see how to replace it here: What does this error message about chromedriver mean?). Of course then I had to downgrade my version of chrome, as well (Version 90.0.4430.93 is working for me).

$\endgroup$
0
$\begingroup$

Mine is version 12.3.1 and session= StartWebSession[ ] opens up the Chrome browser. You can specify other browsers with StartWebSession[“browser”] . To open an url you have to specify the session object. So it’s WebExecute[ session, “OpenPage”->url]

$\endgroup$
1
  • $\begingroup$ Thanks. See my response to Alexey. $\endgroup$
    – jcm
    Jan 21, 2022 at 18:21
0
$\begingroup$

Actually, SystemOpen[] has nothing to do with StartWebSession[].
The function StartWebSession[] comes from WebUnit.m package, which can be verified by using the function PrintDefinitions[] from GeneralUtilities.m package:

Def := GeneralUtilies`PrintDefinitions;
Def[StartWebSession];

After viewing the definition of StartWebSession, we can immediately know where it began to go wrong:
the inner function WebUnit`Private`chooseBrowser and WebUnit`Private`findDriver seems not smart as we expect, it only search several fixed paths.

To fix this problem, we may change the values of these two variable into the path of your own webbrowser:

  1. paths of function chooseChrome[] or chooseFirefox[] of package PATH\wdSession.m
  2. probableLocations of function findBrowserVersion[] of package PATH\wdManageDrivers.m

where PATH := $UserBaseDirectory\Paclets\Repository\WebUnit-1.1.13\Kernel

PS: you may not worry about the path of your webdriver, mma will download the corresponding version if it can't find it, so the only thing you should confirm is that the old version's webdriver and its parent directory can't exist at the same time.(because the source code don't examine version)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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