Thanks for all your help on this - I wouldn't have gotten this far
without it. I have attached to an onclick of a link, and the function
is being called. My only remaining issue is a missing 'event' object
in the js. This is on ie. Here is the js function being attached to
onclick:

    onclick_js =   "function(){"
    onclick_js =   "  alert('button clicked');"
    onclick_js +=  "  event = window.event;"
    onclick_js +=  "  if(event){"
    onclick_js +=  "    alert('found event');"
    onclick_js +=  "  } else { "
    onclick_js +=  "    alert('no event available'); "
    onclick_js +=  "  }"
    onclick_js +=  "}"

I get the alert 'button clicked' and then 'no event available'.

Has anyone tried this and/or have any ideas on what to try. (I have
tried passing event as a parm to the funcion - no difference).

In case it helps, here is the code that attaches this js to the
onclick.

    js = "var top_frame=document.getElementById('top_frame');"
    js +="if(top_frame){"
    js +="  var myelem=top_frame.contentWindow.document.getElementById
('" + html_id  + "');"
    js +="  if(myelem){ "
    js +="    myelem.onclick=" + onclick_js + ";"
    js +="  }"
    js +="};"

    #puts "exec_js is " + js

    SITE.browser.document.parentWindow.execScript(js, "javascript")

On Mar 11, 1:04 pm, andrew.d...@lthree.com wrote:
> Here is a sample. This code does not throw any exceptions. js1,2,3 all
> result in a popup. js 4 does not - indicating that it is not finding
> the element I want. I gaurantee that the html element I am looking for
> is a child of top_frame. In fact, the code that calls this block
> checks that the html element exists using watir.
>
> js1= "alert('hi');"
>
> js2 = "var top_frame=document.getElementById('top_frame'); if
> (top_frame){alert('found top');};"
>
> js3 = "var top_frame=document.getElementById('top_frame'); if
> (top_frame){var myelem = top_frame.document.getElementById('" +
> html_id  + "'); alert('found top');};"
>
> js4 = "var top_frame=document.getElementById('top_frame'); if
> (top_frame){var myelem = top_frame.document.getElementById('" +
> html_id  + "'); if(myelem){ alert('found elem');}};"
>
> js = js4;
>
> puts "my js for " +  html_id + " is " + js
> SITE.browser.document.parentWindow.execScript(js, "javascript")
>
> Any ideas on what I should be using to access an element inside a
> frame? Note: I already tested without all the frame stuff, and it
> doesn't work either.
>
> Andy
>
> On Mar 11, 10:58 am, Andy Sipe <ajs.gene...@gmail.com> wrote:
>
>
>
> > Post a sample of your code.
>
> >  Remember that when you inject the JS you are working only with the dom and
> > the browser JS engine.  Nothing watir related.  The error your are posting
> > leads me to believe that somewhere  you are treating something that should
> > be JS as something in ruby.
>
> > -andy
>
> > On Wed, Mar 11, 2009 at 12:25 PM, <andrew.d...@lthree.com> wrote:
>
> > > Yea, I remembered that 2 secs after posting.
>
> > > Does anyone know anyway to debug js being run with execScript?
>
> > > I am getting
>
> > >      execScript
> > >          OLE error code:80020101 in <Unknown>
> > >            Could not complete the operation due to error 80020101.
> > >          HRESULT error code:0x80020009
> > >            Exception occurred. (WIN32OLERuntimeError)
> > >      C:/workspace/Guidewire/Common/lib/pages/GuidewirePage.rb:313:in
> > > `method_mi
> > > ssing'
>
> > > Note: I can get some js to work, such as alert('hi'), but it always
> > > fails when I use getElementById('someid')
>
> > > On Mar 11, 9:30 am, Andy Sipe <ajs.gene...@gmail.com> wrote:
> > > > lower case 'd'
>
> > > > @ie.document
>
> > > > Sorry about that.
>
> > > > -andy
>
> > > > On Wed, Mar 11, 2009 at 11:02 AM, <andrew.d...@lthree.com> wrote:
>
> > > > > When I tried this I got
>
> > > > >      undefined method `Document' for #<Watir::IE:0x4288648>
> > > > > (NoMethodError)
>
> > > > > Is Watir::IE the correct object to be using here?
>
> > > > > On Mar 11, 8:53 am, Andy Sipe <ajs.gene...@gmail.com> wrote:
> > > > > > You should be able to read it using xpath or some other technique.
>
> > > > > > I don't believe you can set it directly with watir.  However you can
> > > > > always
> > > > > > inject javascript that will change the handler.  Something like:
>
> > > > > > @ie.Document.parentWindow.execScript("$('eleid').onclick =
> > > > > 'alert('hi');');
>
> > > > > > I didn't test that and I'm pretty sure the embedded " and ' are 
> > > > > > wrong
> > > but
> > > > > > you should be able to get the idea of how to set the handler.
>
> > > > > > -andy
>
> > > > > > On Wed, Mar 11, 2009 at 10:33 AM, <andrew.d...@lthree.com> wrote:
>
> > > > > > > So I am clicking on a link that has an onclick handler. I would
> > > like
> > > > > > > to read/write the onclick handler. Is there a way to get at that.
> > > Just
> > > > > > > trying
>
> > > > > > > element.onclick = "sss"
>
> > > > > > > didn't work and neither did
>
> > > > > > > element.click = "sss"
>
> > > > > > > Is there a way to do this?
>
> > > > > > > Andy- Hide quoted text -
>
> > > > > > - Show quoted text -- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to