How do I open a website in Windows 7?

Asked by Boris

Hi

I want to open a specific website on Windows 7.
I have tried
openApp("http://www.example.com/),
but nothing happens.

The workaround is to press Ctrl-Esc (for the start menu), then type the URL and press enter.
However, I don't like this approach because it is slow and it won't work on Windows XP.

Do you know a way to open websites directly in Windows?

In other scripting languages like AutoHotkey there is a "run" command that will open anything.
If openApp doesn't work, what else will?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Boris
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Since you are asking this in the context of Sikuli, I guess, you want to do some visual automation afterwards with your opened website. So there will be a browser anyway.

So I think it would be straightforward to open the browser first, enter the url and press enter.

I have put this in a def(), since I need it more often: def newWeb(browser, url, fullscreen=True):

On the other hand, its no problem to use your favorite automation tool from within a Sikuli script. I'm doing this with applescript, automator and butler.

Revision history for this message
Boris (eidam02) said :
#2

[QUOTE]Since you are asking this in the context of Sikuli, I guess, you want to do some visual automation afterwards with your opened website. So there will be a browser anyway.[/QUOTE]
Exactly, I want to open a website and get some work done there with Sikuli.

[QUOTE]On the other hand, its no problem to use your favorite automation tool from within a Sikuli script. I'm doing this with applescript, automator and butler.[/QUOTE]
IMHO visual scripting is only superior with respect to websites and such. For opening folders, programs and websites I much prefer the command line approach. if it means that I have to combine Sikuli with another scripting language, I will do that. Thanks for the hint.

[QUOTE]So I think it would be straightforward to open the browser first, enter the url and press enter.[/QUOTE]
This clearly doesn't work in Sikuli, because even a quite standard item such as openApp("iexplore.exe") for Internet Explorer doesn't work at all. Unless I go to the Desktop and doubleclick on the Internet Explorer icon there, which is slow.

I really think that Sikuli should be able to open websites and programs without a visual interface. OpenApp() is supposed to do that, but doesn't work, at least in Windows.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

switchApp/openApp work fine even on Windows (Sorry, I'm a Mac ;-)

openApp(text) on Windows:
text: The name of an application (case-insensitive), that can be found using the environment variable PATH, otherwise the full path to an application (Windows: use double backslash)
Opens the application text and makes it the frontmost having the focus.
examples:
openApp("cmd.exe") # Windows: found thru PATH
openApp("c:\\Program Files\\Mozilla Firefox\\firefox.exe") # windows: full path specified

switchApp(text) on Windows:
text: The name of an application (case-insensitive).
Switches to application text and makes it the frontmost having the focus (Mac: if the app has more than one window open, with means of Sikuli you cannot decide, which one will be the frontmost. Windows: see note blow). If the application is not running, we try to launch it by openApp().
Note for Windows: text is searched in the text on the title bar of the windows of the running applications. So if you are sure, your app is running, text need not be an application name. So if windows of one app have different titles, you can select on of these windows (not possible on Mac).
examples:
switchApp("cmd.exe") # Windows: switches to open command prompt or starts one
switchApp("c:\\Program Files\\Mozilla Firefox\\firefox.exe") # windows: opens a new browser window !! (since text cannot be found in the window title)
switchApp("mozilla firefox") # windows: switches to the frontmost open browser window (no window open: does nothing !!)

your case e.g.:
openApp("c:\\program files\\internet explorer\\iexplore.exe")
sleep(3) # depends on your system speed
type("some url") # works when address field has focus after starting IE

[QUOTE]For opening folders, programs and websites I much prefer the command line approach.
You should have a look at the powerful builtin functions of Python and the modules os and sys, which are available in Sikuli thru Jython. There is no need to call a command line script for all this, everything and even much more can be done in a Sikuli script.

Revision history for this message
Boris (eidam02) said :
#4

RaiMan,
Thanks. This was helpful but I don't have the time to learn Python right now.
I can't even open a website!
Will tinker some more with Sikuli. Has some nice features.
Boris

Revision history for this message
RaiMan (raimund-hocke) said :
#5

Things will even be much better with upcoming version 0.10.

See you later - have a nice time (possible I think without knowing much about python ;-)

Revision history for this message
Arthur Dias (artdias90-deactivatedaccount) said :
#6

So is there any easy way to type the URL ?
I have to use type(img,text) but it won't work case browser layout changes.

Revision history for this message
RaiMan (raimund-hocke) said :
#7

@ Arthur

All actual browsers should accept ctrl-L to get focus on the address field. Then you should use paste() to enter the url.

openApp("your-browser") # should open a new Browser window
wait(5) # make sure window is ready
type("l", KeyModifier.CTRL)
paste("http://some-url.com")

BTW: do not ask questions via a comment to a really ancient question, just make a new question.

Revision history for this message
Arthur Dias (artdias90-deactivatedaccount) said :
#8

yeaahh nice

ok sorry! thanks.

Revision history for this message
xiaominghuang (17212915-k) said :
#9

i want to run 10 times Chrome Browser,but it run 5 times,what will i do?
for i in range(10):
    App.open("Google Chrome.app")
    #print("open Google Chrome" + i)
    wait(1)
    App.close("Google Chrome.app")

Revision history for this message
RaiMan (raimund-hocke) said :
#10

@ xiaominghuang

you have to put a wait(1) after the close() too, to take care, that the next open does not come too fast.

I used wait(2) in both cases: worked perfectly.

Revision history for this message
xiaominghuang (17212915-k) said :
#11

@RaiMan

According to your suggestion,it works well now,thank you!

Revision history for this message
hakim johari (hakim-johari) said :
#12

i try xiaominghuang script but it did not work for me.

[error] App.open failed: Google Chrome.app not found

and i try change it to chrome.exe

[error] App.open failed: chrome.exe not found

Revision history for this message
RaiMan (raimund-hocke) said :
#13

@ hakim
are you on Windows?

you have to use the full path to the .exe in App.open(), since Chrome is not found on system path.

Revision history for this message
hakim johari (hakim-johari) said :
#14

ok i can open browser but how do i close it?

openApp("C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe")
wait(2)
closeApp("C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe")
wait(2)

it didn't give any error but my browser is still open

Revision history for this message
RaiMan (raimund-hocke) said :
#15

@hakim

after having it open, all other app commands have to use a text from the window title.

see http://doc.sikuli.org/globals.html#controlling-applications-and-their-windows

Revision history for this message
hakim johari (hakim-johari) said :
#16

ok got it now thanks :)

Revision history for this message
sumera (sumera-ather) said :
#17

I am running this thing
openApp("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
type("l", KeyModifier.CTRL)
paste("https://www.google.ca/")

My chrome browser is opened but google is not being loaded. Please help

Revision history for this message
Rocky (asingh2783) said :
#19

hi everyone,

I have apparently complicated issue but yet a simple setup issue.

My main project has following structure .

ABC.sikuli |-------ABC.py (openApp ("notepad") works fine )
                      |-------ABC.html
                      |-------Modules|-------Module1.py (openApp ("notepad") does not work )
                                                 |-------Module2.py (openApp ("notepad") does not work )
                                                 |-------Module3.py (openApp ("notepad") does not work )

am i missing something in setting the project properly ?
can someone please point me to the correct way of achieving this project layout ?
All i want is to have sikuli function available to my modules are well . right now they are available in only ABC.py defined beneath ABC.sikuli .