Chrome AutoOpen via Sikulix

Asked by Pritam Biswas on 2019-12-20

Dear All,

I want to check if Chrome is open or not,
> if open, add a new tab and type some URL, hit enter- This Part is working fine with the below snippet.
>If Chrome is closed then first open it, and add a new tab type some URL and hit enter/type the URL in the same tab and hit enter. The below snippet is failing to do this part.

ac = App("Google Chrome")
if ac.window(): # already open?
  ac.focus() # then just switch to it
else: # not yet open
 ac.open()
 while not ac.window(): wait(1)

# now the chrome window is frontmost
type("t",KEY_CTRL)
type("l", KeyModifier.CTRL)
type("http://some-url.com")
type(Key.ENTER)
wait(3)

Any leads will be appreciated to let me know where i'm doing it wrong.

Regards,
Pritam

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2019-12-23
Last query:
2019-12-23
Last reply:
2019-12-23
RaiMan (raimund-hocke) said : #1

what SikuliX? What system? What Java?

Pritam Biswas (pritam-b) said : #2

what SikuliX? -2.0.1
What system?- Windows 10 Enterprise Edition
 What Java?- JDK 1.8

Best RaiMan (raimund-hocke) said : #3

This is how you should do it with SikuliX 2.x+

chrome = App("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
if not chrome.isRunning():
  print "closed - will open it"
  chrome.open(10)
  if not chrome.isRunning():
    print "still closed"
    exit()
print "running"
chrome.focus()
type("t",Key.CTRL)
type("l", Key.CTRL)
type("http://some-url.com")
type(Key.ENTER)
wait(3)

for the details see the docs

Pritam Biswas (pritam-b) said : #4

Thanks Raiman.
But this snippet gives me problem if Chrome is closed. It types the URL in some file explorer then getting out of this code.
If Chrome is open then it's working perfectly.

RaiMan (raimund-hocke) said : #5

Then you should check again and run it step by step.

For me it worked in every situation.

RaiMan (raimund-hocke) said : #6

... check the path to Chrome - might be different on your machine.

RaiMan (raimund-hocke) said : #7

Uuups, strange: (did a copy&paste of the running script)

must be:
chrome = App(r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")

to get the backslashes down to the runner.

Pritam Biswas (pritam-b) said : #8

Thanks. I found out the issue. In my VM there was a setting enabled that was letting Chrome run in the background which is why it wasn't working properly. After i disabled the setting this script is working perfectly.

Pritam Biswas (pritam-b) said : #9

Thanks RaiMan, that solved my question.