Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

How to grab the value of the span element using jQuery

I have the following code:

<tr>
<td Width="50%" align="left">
<span id="ctl00_lblTotalDesc">Ext. Subtotal</span></td>
<td Width="50%" align="right">
<span id="ctl00_lblTotalValue">100,087,000.00</span></td>
</tr>

I used the following to grab the value of the 2nd span element:

spanValue = $('#ctl00_lblTotalValue').text();

But this doesn't seem to work in Spock/Geb. I get the following error:

TypeError: $(...).text is not a function

What am I doing wrong

I get the following error if I use, $('#ctl00_lblTotalValue')

[object HTMLTableElement]

Firefox console was not useful so used Chrome console.

In Chrome: if I try $('#ctl00_lblTotalValue'), I get

<span id="ctl00_lblTotalValue">100,087,000.00</span>

But .text() - gives Type error: Object # has no method 'text'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It seems you have another js framework overriding the $ function. it means you have to use jQuery('...') instead. The other point you have to consider is, as far as I know in all js frameworks I've worked with, the $ function does the same thing, but sometimes it selects the first matched html element then when your output is like:

[object HTMLTableElement]

it means the html object is not a span element. try:

$('#ctl00_lblTotalValue').length

if the result was greater than 1, it mean you have more than one html element with this same id.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...