Watir with javascript?

I have been using the watir gem for a few days, and i have come across a
problem with Javascript. I trying to do things like click on text
attributes, ect. I saw something in the watir examples but I’m not sure
it’s exactly what I’m looking for. Any know how to use those commands
with javascript???

On Aug 15, 4:55 pm, Erik B. [email protected] wrote:

I have been using the watir gem for a few days, and i have come across a
problem with Javascript. I trying to do things like click on text
attributes, ect. I saw something in the watir examples but I’m not sure
it’s exactly what I’m looking for. Any know how to use those commands
with javascript???

Posted viahttp://www.ruby-forum.com/.

you shoud post this to the watir group -
http://groups.google.com/group/watir-general?lnk=srg
Also please show some html/code etc as thats far moremeaningful than
saying you want to click on some text

Paul

you shoud post this to the watir group -
http://groups.google.com/group/watir-general?lnk=srg
Also please show some html/code etc as thats far moremeaningful than
saying you want to click on some text

Paul

Sorry for not being specific enough :(. Ok i’ll start off with what
exactly i want to do, my friend playing a game called runescape you
may of heard of it? Anyways, i thought it would be cool if i could write
him a program using watir that would go onto the site, and navigate
though, and logg him in. totally pointless, but doing little projects
like this is the only way can really learn

Here’s there first link i want to click on:
li class=“i-play”>Play RuneScape (Existing
user)

You can pass click events with Watir pretty easily. As far as
javascript is concerned, you can directly manipulate it via watir,
but usually, why bother?

Now, for more advanced questions, and future ones, yea ask on the
watir mailing list.

Anyway, in this case, your problems aren’t with watir, they’re with a
VERY poorly constructed website. I just took a look at it, and I
mean, yuck.
Load it irb, and look at the page that way, everything is actually in a
frame!
$ie=Watir::IE.start(“http://www.runescape.com”)
$ie.link(:text,/play runescape/i).click
#oops, that should work, but it doesn’t! Humm
$ie.show_frames
there are 1 frames
frame index: 1 name:
#Ahh!
$ie.frame(‘’).link(:text,/play runescape/i).click
#yes. It’s that bad/poorly written. While there is a decent defense
of using frames, not giving labels and ids to things is just bad.
#ayway, that’s the first of two play runescape links, you can get to
the second one this way
#and then use any of the regular methods on it you wish, like click or
flash or html or whatever.
$ie.frame(‘’).link(:text=>/play runescape/i,:index=>2)

–Kyle

frame!
$ie=Watir::IE.start(“http://www.runescape.com”)
$ie.link(:text,/play runescape/i).click
#oops, that should work, but it doesn’t! Humm
$ie.show_frames
there are 1 frames
frame index: 1 name:
#Ahh!
$ie.frame(‘’).link(:text,/play runescape/i).click
#yes. It’s that bad/poorly written. While there is a decent defense
of using frames, not giving labels and ids to things is just bad.
#ayway, that’s the first of two play runescape links, you can get to
the second one this way
#and then use any of the regular methods on it you wish, like click or
flash or html or whatever.
$ie.frame(‘’).link(:text=>/play runescape/i,:index=>2)

–Kyle

Ok… right now… i think I’m going insane or something???
So at first i try
require ‘watir’
$ie=Watir::IE.start(“http://www.runescape.com”)
$ie.link(:text,/play runescape/i).click
works brilliantly,
so i went farther into the site (choosing detail)
so i add on
require ‘watir’
$ie=Watir::IE.start(“http://www.runescape.com”)
$ie.link(:text,/play runescape/i).click
ie.button(:value, “low detail”).click
once again… great success *i don’t think i added the $ infront of the
ie.button?
so i go to choose a world… doesn’t work… so i tried just choosing
detail… nothing… i tried just doing what Kyle 1st said,
require ‘watir’
$ie=Watir::IE.start(“http://www.runescape.com”)
$ie.link(:text,/play runescape/i).click…
NOW NOTHING WORKS, i know I’m overreacting… but this just for some
reason is really bugging me… heres the error i get.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Schmode>cd\

C:>hell.rb
./watir.rb:1928:in assert_exists': Unable to locate object, using text and (?i- mx:play runescape (existing user)) (Watir::Exception::UnknownObjectException) from ./watir.rb:2009:in click’
from C:/hell.rb:3

C:>
Much thanks for anyone that helps :slight_smile:

First a bit of general ruby stuff:
The $ infront of ie means it’s global.

That can be useful when writing little one off methods for your
automation in irb, or when you’re writing a script.
Does that help?

See,
foo=:local
$foo=:global
@foo=:class
@@foo=:shared_between_all_instances_of_class
These are all different variables, they can each store a different
value, and have their own rules about where/when you can access them.
Try this
foo=“local variable”
$foo=“huge global variable”
@foo=“class variable (but we can abuse it and treat it as global in
small scripts)”

def up()
$foo.upcase!
@foo.upcase!
end
up()
puts $foo
puts @foo
#now try
def bad
foo.upcase!
end
bad()
#You get an error here, since foo is local, it doesn’t exist in the
method!
#if this doesn’t make much sense, try some of the 30 minute type ruby
#tutorials. I think it’s hard to learn watir without a handle on the
basics of ruby :slight_smile:

Now, onto the rest of it.
Humm, that showed up as a frame for me, but maybe they did some update?
Now, inside of irb, you only require watir once, doing it more than
once, won’t hurt, but it will cough a bit.

Watir provides some nice .exists? methods; very useful when prodding
and poking a website with irb/watir.
$ie.link(:text,/play runescape/i).exists?
#That will tell you whether or not it exists!
#A quick & dirty thing to see all links is
$ie.links.each{|link| puts link}
#but my guess is that its in another stupid frame so if the previous
line
#doesn’t have the link you want, try
$ie.showFrames()

Well, i fixed it i was being a complete tard, and typed in ie.link, not
ie.frame. some how this got messed up from there? i don’tknow… maybe i
was going insane washing too many dishes @ my summer job??? :stuck_out_tongue:
Anyways… things are working awesome, took me a looong time to figure
out that not all the things there are links, some are buttons, which
meant that i had to use :value not :text…
On a side not and as an attempt not to spam the forums I’m reading
this online book, Programming Ruby : the pragmatic program and i came
across attributes.
class Song
def duration
@duration
end
end
aSong = Song.new(“Bicylops”, “Fleck”, 260)
aSong.duration » 260
Now to me theses look a lot like what my cousin was calling “keywords”
like .zip and what not. are these the same thing but the keywords or
built in attributes?