jQuery contains Element finding.

6 posts, 1 answers
  1. Anton
    Anton avatar
    54 posts
    Member since:
    Sep 2011

    Posted 04 Dec 2012 Link to this post

    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.
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 06 Dec 2012 Link to this post

    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
  3. Anton
    Anton avatar
    54 posts
    Member since:
    Sep 2011

    Posted 06 Dec 2012 Link to this post

    Hi Boyan,
    Thanks for answer.

    Yeah, i know it, but i want to know how i can do it through C# code!?
  4. Anton
    Anton avatar
    54 posts
    Member since:
    Sep 2011

    Posted 07 Dec 2012 Link to this post

    Or for example i need to click at anchor in last "td".
  5. Answer
    Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 10 Dec 2012 Link to this post

    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
  6. Anton
    Anton avatar
    54 posts
    Member since:
    Sep 2011

    Posted 10 Dec 2012 Link to this post

    Thanks Boyan,
    It's worked.
Back to Top