accessing the element of a span

M

Mike Hin

I'm trying to test against the class name of a span. I'm iterating
through all spans and basically want to say, "If ie.spans[x]'s value for
class = "SSSBUTTON_CONFIRMLINK" then return the inner text of the span"

print ie.spans[x] returns the following

type:
id:
name:
value:
disabled: false
class: SSSBUTTON_CONFIRMLINK
text: Start a New Search

Anyone know how to accomplish this? I haven't been able to figure out
the command to return the class name of a span. I know ie.spans[x].text
will return the inner text but I don't know the code for any of the
other attributes. i tried using :class also to no avail.

Thanks for any help,
Mike
 
J

Jesús Gabriel y Galán

I'm trying to test against the class name of a span. I'm iterating
through all spans and basically want to say, "If ie.spans[x]'s value for
class =3D "SSSBUTTON_CONFIRMLINK" then return the inner text of the span"

print ie.spans[x] returns the following

type:
id:
name:
value:
disabled: =A0 =A0 false
class: =A0 =A0 =A0 =A0SSSBUTTON_CONFIRMLINK
text: =A0 =A0 =A0 =A0 Start a New Search

Anyone know how to accomplish this? I haven't been able to figure out
the command to return the class name of a span. I know ie.spans[x].text
will return the inner text but I don't know the code for any of the
other attributes. i tried using :class also to no avail.

What is "ie"? You don't specify which libraries you are using. Unless
you give a little bit more detail it's difficult to help.

Jesus.
 
M

Mike Hin

Oh wow, thats what I get for posting at 3am. I am using Watir and ie is
the browser being driven. sorry.

Jesús Gabriel y Galán said:
disabled: � � false
class: � � � �SSSBUTTON_CONFIRMLINK
text: � � � � Start a New Search

Anyone know how to accomplish this? I haven't been able to figure out
the command to return the class name of a span. I know ie.spans[x].text
will return the inner text but I don't know the code for any of the
other attributes. i tried using :class also to no avail.

What is "ie"? You don't specify which libraries you are using. Unless
you give a little bit more detail it's difficult to help.

Jesus.
 
7

7stud --

Mike said:
I'm trying to test against the class name of a span. I'm iterating
through all spans and basically want to say, "If ie.spans[x]'s value for
class = "SSSBUTTON_CONFIRMLINK" then return the inner text of the span"

print ie.spans[x] returns the following

type:
id:
name:
value:
disabled: false
class: SSSBUTTON_CONFIRMLINK
text: Start a New Search

Anyone know how to accomplish this? I haven't been able to figure out
the command to return the class name of a span. I know ie.spans[x].text
will return the inner text but I don't know the code for any of the
other attributes. i tried using :class also to no avail.

Thanks for any help,
Mike

Try something like this(untested):

ie.spans.each do |span|
if span.class == "SSSBUTTON_CONFIRMLINK"
span.text
end
end
 
M

Mike Hin

That was the first thing I tried, span.class simply returns Watir::Span
showing that the object in span is of the Watir::Span class.
 
7

7stud --

Mike said:
That was the first thing I tried, span.class simply returns Watir::Span
showing that the object in span is of the Watir::Span class.

With such poor documentation, I wonder why anyone would use Watir over
Hpricot or Nokogiri. In any case, here are two more things you can try:

span.class_name
span.attribute_value("class")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top