Need to click on a link which has only the class name.

17 views
Skip to first unread message

Mahesh

unread,
Jun 15, 2011, 3:27:38 AM6/15/11
to Watir General
Hi,

<LI class="x-tab-strip-closable x-tab-with-icon x-tab-strip-active "
id=mainTabsId__CaseDetails><A class=x-tab-strip-close onclick="return
false;"></A>

This is the source code, and i am using the if condition to extract
the dynamic class name to extract the class name & click the link.

The Watir script i am using is:

if /<LI class=.*id=mainTabsId__CaseDetails><A class=(\S*) onclick=.*>/
begin
ie.link(:class, $1).click
rescue => e
rescueHandle(e)
end
else
puts "FAILED! Could not find Class for Close Button"
return false
end

Ashok Tulachan

unread,
Jun 15, 2011, 9:20:33 AM6/15/11
to watir-...@googlegroups.com
What's the source code for your link???
 
Ashok




--
Regards,
 
Ashok Tulachan
 

Mahesh

unread,
Jun 15, 2011, 10:27:45 AM6/15/11
to Watir General
Ashok, this is the source code:

<LI class="x-tab-strip-closable x-tab-with-icon x-tab-strip-active "
id=mainTabsId__CaseDetails><A class=x-tab-strip-close onclick="return
false;"></A>

On Jun 15, 6:20 pm, Ashok Tulachan <tulachanas...@gmail.com> wrote:
> What's the source code for your link???
>
> Ashok
>
>
>
> On Wed, Jun 15, 2011 at 2:27 AM, Mahesh <mahesh...@gmail.com> wrote:
> > Hi,
>
> > <LI class="x-tab-strip-closable x-tab-with-icon x-tab-strip-active "
> > id=mainTabsId__CaseDetails><A class=x-tab-strip-close onclick="return
> > false;"></A>
>
> > This is the source code, and i am using the if condition to extract
> > the dynamic class name to extract the class name & click the link.
>
> > The Watir script i am using is:
>
> > if /<LI class=.*id=mainTabsId__CaseDetails><A class=(\S*) onclick=.*>/
> >                begin
> >                        ie.link(:class, $1).click
> >                rescue => e
> >                        rescueHandle(e)
> >                end
> >        else
> >                puts "FAILED! Could not find Class for Close Button"
> >                return false
> >        end
>
> > --
> > Before posting, please readhttp://watir.com/support. In short: search

Ashok Tulachan

unread,
Jun 15, 2011, 1:38:43 PM6/15/11
to watir-...@googlegroups.com
<LI class="x-tab-strip-closable x-tab-with-icon x-tab-strip-active "
id=mainTabsId__CaseDetails><A class=x-tab-strip-close onclick="return
false;"></A>
 
 
Mahesh, If that's the link source code then,
 
Try this,
 
if ie.link(:class, "x-tab-strip-closable x-tab-with-icon x-tab-strip-active").exist? == true
            begin
                 ie.link(:class, "x-tab-strip-closable x-tab-with-icon x-tab-strip-active").click

              rescue => e
                  rescueHandle(e)
              end
     else
         puts "FAILED! Could not find Class for Close Button"
             return false
      end

Let me know if it works.
 
Ashok



--
Regards,
 
Ashok Tulachan
 

Chuck van der Linden

unread,
Jun 15, 2011, 3:30:01 PM6/15/11
to Watir General
You say you are dynamically extracting the class of the link, does
this mean it is changing in a regular basis?

I'm having a hard time following exactly what your challenge is here,
What do you know, e.g. what is constant each time or predictable each
time? how do you know you've found the link you want to click?

If the pattern is for example a list item with a particular ID, that
contains the link you want, and the class of the link always contains
the text "...strip-close" then you could do something like this

if browser.li(:id, mainTabsId__CaseDetails').link(:class, /strip-
close/).exists?
browser.li(:id, mainTabsId__CaseDetails').link(:class, /strip-
close/).click
else
puts "FAILED! Could not find Close Button"
return false
end


orde

unread,
Jun 16, 2011, 1:33:24 PM6/16/11
to Watir General
I'd agree with the post above. Unless you have some other compelling
reason, the approach above should be fine.

In any event, $1 is returning nil in this code snippet:

if /<LI class=.*id=mainTabsId__CaseDetails><A class=(\S*)
onclick=.*>/
begin
ie.link(:class, $1).click
rescue => e
rescueHandle(e)
end
else
puts $1 # nil
puts "FAILED! Could not find Class for Close Button"
return false
end

Reply all
Reply to author
Forward
0 new messages