[Wtr-general] Calling JavaScript code in the browser
Egil Sorensen
egil at yahoo-inc.com
Thu Sep 7 20:12:08 EDT 2006
Thanks to Bill Attebery for pointing to a blog with a good solution to this
problem. I have experimented with making it easier to get any return value
back to Watir. This is what I came up with:
===================================
require 'watir'
module Watir
class IE
def execute_script(scriptCode)
ie.Document.parentWindow.execScript("window.WatirJSResult =
"+scriptCode)
return ie.Document.parentWindow.WatirJSResult
end
end
end
===================================
This allows for dropping an extra step in the test from the blog to relay
the result. The test now simply becomes:
===================================
def test_selection
@ie.execute_script("RadComboBox1.FindItemByText(\"Golf\").Select()")
assert_equal("Golf", @ie.execute_script("RadComboBox1.GetText()"))
end
===================================
I am no JavaScript expert, and I have only used this in a few small tests,
so I don't know if this will get me in trouble anywhere, though.
~~ Egil
> -----Original Message-----
> From: "Attebery, Bill" <Bill.Attebery at twtelecom.com>
> Subject: Re: [Wtr-general] Cannot access input element
>
> I thought I posted this a month or so back but I can't find it.
>
> Check out
> http://blogs.telerik.com/blogs/twisted_asp_net/archive/2006/04/26/201.aspx
> this is where I found out how to get to the window object and call the
> execScript method.
> (...)
More information about the Wtr-general
mailing list