[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Watir : Working in same session of IE

Anukul Singhal

4/30/2008 9:52:00 AM

Hi,

Actually am stuck in a problem.

I am performing the following set of commands:

require 'watir'

ie = Watir::IE.new
ie.goto("http://www.google...)

When I execute, it successfully opens a new browser with the correct
google url.

Now, in this code, I simply want to add:

ie.text_field(:name, "q").set 'roger federer'

If I append the above line to the above code, it will open a new session
of IE and will perform the operation of setting the text box too, but my
objective is not to open a new IE with google url but to perform the set
command in the existing browser only.

Can anyone help how to do that?

Thanks,
Anukul
--
Posted via http://www.ruby-....

3 Answers

Peña, Botp

4/30/2008 10:03:00 AM

0

RnJvbTogbGlzdC1ib3VuY2VAZXhhbXBsZS5jb20gDQojIEFjdHVhbGx5IGFtIHN0dWNrIGluIGEg
cHJvYmxlbS4NCiMgSSBhbSBwZXJmb3JtaW5nIHRoZSBmb2xsb3dpbmcgc2V0IG9mIGNvbW1hbmRz
Og0KIyByZXF1aXJlICd3YXRpcicNCiMgaWUgPSBXYXRpcjo6SUUubmV3DQojIGllLmdvdG8oImh0
dHA6Ly93d3cuZ29vZ2xlLmNvbSIpDQojIFdoZW4gSSBleGVjdXRlLCBpdCBzdWNjZXNzZnVsbHkg
b3BlbnMgYSBuZXcgYnJvd3NlciB3aXRoIHRoZSBjb3JyZWN0DQojIGdvb2dsZSB1cmwuDQojIE5v
dywgaW4gdGhpcyBjb2RlLCBJIHNpbXBseSB3YW50IHRvIGFkZDoNCiMgaWUudGV4dF9maWVsZCg6
bmFtZSwgInEiKS5zZXQgJ3JvZ2VyIGZlZGVyZXInDQojIElmIEkgYXBwZW5kIHRoZSBhYm92ZSBs
aW5lIHRvIHRoZSBhYm92ZSBjb2RlLCBpdCB3aWxsIG9wZW4gYSANCiMgbmV3IHNlc3Npb24gb2Yg
SUUgDQoNCnRoYXQncyB3ZWlyZC4gaSBqdXN0IHRyaWVkIHlvdXIgY29kZSwgYW5kIGl0IGRvZXMg
Km5vdCBvcGVuIGFub3RoZXIgKG5ldykgc2Vzc2lvbiAoaW4gdGhhdCBjYXNlLCBpIG9ubHkgaGF2
ZSAxIGllIHNlc3Npb24gb3Blbiwgbm90IDIpLg0KDQpraW5kIHJlZ2FyZHMgLWJvdHANCg==

Anukul Singhal

4/30/2008 10:13:00 AM

0

Peña, Botp wrote:
> From: list-bounce@example.com
> # Actually am stuck in a problem.
> # I am performing the following set of commands:
> # require 'watir'
> # ie = Watir::IE.new
> # ie.goto("http://www.google...)
> # When I execute, it successfully opens a new browser with the correct
> # google url.
> # Now, in this code, I simply want to add:
> # ie.text_field(:name, "q").set 'roger federer'
> # If I append the above line to the above code, it will open a
> # new session of IE
>
> that's weird. i just tried your code, and it does *not open another
> (new) session (in that case, i only have 1 ie session open, not 2).
>
> kind regards -botp

Hi botp,

Are you trying this out in Scite or is their something else that you are
using?I believe when you execute (F5) the first two lines of code, it
will open IE with google url.

Now, with the google url already open, I want to update the code in such
a way that I can enter the text in the search field without opening a
new session of the browser. So, if I just add the 3rd line of my code
and execute, it would definitely open a new instance of IE (since it
will execute ie = Watir::IE.new again). I want to avoid that, hoping
that there must be a logic between the first 2 lines and the 3rd line
which avoids opening a new browser.

Another idea would be to check if there is an existing instance of IE
already present and then we can just do ie.goto(url).

Can you help with the logic?

Thanks,
Anukul
--
Posted via http://www.ruby-....

aidy

4/30/2008 12:24:00 PM

0

On 30 Apr, 10:52, Anukul Singhal <anukul.sing...@gmail.com> wrote:
> require 'watir'
>
> ie = Watir::IE.new
> ie.goto("http://www.google...)
> When I execute, it successfully opens a new browser with the
> correct google url.
> Now, in this code, I simply want to add:
> ie.text_field(:name, "q").set 'roger federer'
> If I append the above line to the above code, it will open a new > session
> of IE and will perform the operation of setting the text box too, > but my
> objective is not to open a new IE with google url but to perform > the set command in the existing browser only.

It might have been better to post this on the Watir list; you can
subscribe here;
http://wtr.rubyforge.org/comm...

I think Ruby linguistic answers would be best answered at ruby.lang.

If we look at the Watir API doc
http://wtr.rubyforge...

we note ie.attach

"Return a Watir::IE object for an existing IE window. Window can be
referenced by url, title, or window handle. Second argument can be
either a string or a regular expression in the case of of :url
or :title. IE.attach(:url, ‘www.google.com’) IE.attach(:title,
‘Google’) IE.attach(:hwnd, 528140) This method will not work when
Watir/Ruby is run under a service (instead of a user). "

Regards

Aidy
www.agiletester.co.uk