This is a migrated thread and some comments may be shown as answers.

jQuery contains Element finding.

5 Answers 219 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 04 Dec 2012, 05:01 PM
Hello.
I have a problem to find element with jQuery.

HTML:
<table id="descriptorTable" class="rf-dt table table-striped">
<colgroup span="5"></colgroup>
<thead id="descriptorTable:th" class="rf-dt-thd">
<tbody id="descriptorTable:tb" class="rf-dt-b">
<tr class="rf-dt-r rf-dt-fst-r">
<td id="descriptorTable:0:j_idt664" class="rf-dt-c" style="text-align: center;">
<input type="checkbox" onclick="updateButtonState()" name="descriptorTable:0:j_idt665">
</td>
<td id="descriptorTable:0:j_idt666" class="rf-dt-c" style="text-align: center;">ANEEIGP</td>
<td id="descriptorTable:0:j_idt668" class="rf-dt-c" style="text-align: center;">2</td>
<td id="descriptorTable:0:j_idt670" class="rf-dt-c" style="text-align: center;">
<td id="descriptorTable:0:j_idt672" class="rf-dt-c" style="text-align: center;">
</tr>
<tr class="rf-dt-r firefinder-match">
</tbody>
<tbody id="descriptorTable:sc">
</table>

I need to get CheckBox in a row in which in second cell text equal to some text.
My real jQuery wihich work in FireBug is : 
$('#descriptorTable tr:contains(\'ANEEIGP\') input');

But when i try to convert it to WebAii jQuery it return ObjRefException.
Find.ByExpression<HtmlControl>("id=descriptorTable", "|", "tagindex=tbody:0").
Find.jQuery().tag("tr").contains(closedProejct).first<HtmlTableRow>().
            Find.ByExpression<HtmlInputCheckBox>("tagname=input").Check(true, true);

i can find cell with this text but i cant get checkbox, because of i cant get parent element of cell.
Find.ByExpression<HtmlControl>("id=descriptorTable", "|", "tagindex=tbody:0").Find.jQuery().tag("tr").descendant()
               .contains(closedProejct).parent().tag("tr").first<HtmlTableRow>().
           Find.ByExpression<HtmlInputCheckBox>("tagname=input").Check(true, true);

I know i can get it with LINQ and Find Expressionsm but i want to know how i can get it with WebAii jQuery.
Thanks.

5 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 06 Dec 2012, 01:38 PM
Hi Anton,

There is a much easier way to achieve this this. Just implement a single javaScript function with your working jQuery. In your case:


function myFunction(){
$('#descriptorTable tr:contains(\'ANEEIGP\') input').attr('checked', true);
}

Telerik Testing Framework supports directly invoking JavaScript functions from your .NET test code. So add this simple code in your test step:

Actions.InvokeScript("myFunction()");

This will invoke the function and check your checkbox.

Let me know if this helps.
All the best,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Anton
Top achievements
Rank 1
answered on 06 Dec 2012, 01:50 PM
Hi Boyan,
Thanks for answer.

Yeah, i know it, but i want to know how i can do it through C# code!?
0
Anton
Top achievements
Rank 1
answered on 07 Dec 2012, 11:32 AM
Or for example i need to click at anchor in last "td".
0
Accepted
Boyan Boev
Telerik team
answered on 10 Dec 2012, 01:23 PM
Hi Anton,

Please excuse me for the delayed reply. Please try out this code in C#.

Find.ByExpression<HtmlControl>("id=descriptorTable", "|", "tagindex=tbody:0").
Find.jQuery().tag("td").contains("ANEEIGP").first<HtmlTableCell>().
Parent<HtmlTableRow>().Find.ByExpression<HtmlInputCheckBox>("tagname=input").Check(true, true);

First find the "td" that contains "ANEEIGP" and then find the "input" element in its parent element which is is a "tr" element.

Regarding to your second post, you can click on the last "td" via this code:

Find.ByExpression<HtmlControl>("id=descriptorTable", "|", "tagindex=tbody:0").Find.jQuery().tag("td").
last<HtmlTableCell>().Find.ByExpression<HtmlAnchor>("tagname=a").Click();

Hope this helps. Regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Anton
Top achievements
Rank 1
answered on 10 Dec 2012, 01:41 PM
Thanks Boyan,
It's worked.
Tags
General Discussions
Asked by
Anton
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Anton
Top achievements
Rank 1
Share this question
or