how to set the URL

Asked by kishore

hI,

How to open IE Browser and set the url without taking screen shot of URL Location,

Could you please provide code for that

Regards,
Kishore

Question information

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

comment on behavior:
- you should comment your answered questions and/or set them to solved if so
- have a look at the docs and this board, before asking basic questions (other people, who may answer your questions have done this also)

- to open an application: use the App class features
- to enter an url to a browser: get the window frontmost and use type("l", KeyModifier.CTRL) on windows to position to the address field

Revision history for this message
kishore (kishore-thotapally) said :
#2

Raiman,

I tried the following code by using function to pass the url but i am getting the following error

Function
def OpenBrowser(url):
     print(url)
     myApp = App("iexplore")
     if not myApp.window(): # no window(0) - Firefox not open
        App.open("C:\Program Files\Internet Explorer\iexplore.exe")
        wait(8)
        myApp.focus()
        wait(1)
        type("l", KEY_CTRL)
        type(url+Key.ENTER)
        wait(10)

Note : Url value getting from .xls file

main script : Global.OpenBrowser(url)

Error : type(url+Key.ENTER) TypeError: unsupported operand type(s) for +: 'NoneType' and 'unicode'

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

Seems that url has no value at that time.

You have a "print url" (no brackets needed) at the beginning. What is printed?

Nevertheless look faq 933 for problems with type().

instead use:
paste(url); type(Key.ENTER)

One more thing: I suggest:
        type("l", KEY_CTRL); wait(1)

Revision history for this message
kishore (kishore-thotapally) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
Ken Mayer (kmayer) said :
#5

The following code will work only for Windows systems, but it is an easy way to open a URL from Sikuli. Since I didn't find the whole answer anywhere, here's what worked for me. I used os,popen() to open cmd and start a url in the default browser.

#example1 -- raw string
import os
# Note that because the ampersand ("&") is reserved in Batch file processing
# the ampersands in the query string need to have a caret (^) in front of them
cmd = r'start /B "" "http://annapolis.craigslist.org/search/msa?query=mandolin^&maxAsk=200"'
os.popen(cmd);

# example2 -- concatenation
import os
# with a variable URL, I opted not to mess with raw string format, but just concatenated these into the mix
urlVariable[recordsCount] = 'http://annapolis.craigslist.org/search/msa?query=mandolin^&maxAsk=200'
cmd1 = 'start /B \"\" \"'
cmd2 ='\"'

os.popen(cmd1+ urlVariable[recordsCount] +cmd2);

I hope this helps!

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

With version 1.0.1 you could simply use:

if the url string contains blanks

run('start "' + url "')

or
run ("start " + url.replace(" ", "%20"))

if you are sure there are no blanks, this would be sufficient:
run ("start " + url)

this is for Windows.

For Mac use open instead of start.

This will open the url in your standard browser.

This works now, because I reworked the run command completely.