How to select the second tr of my HTML?












3














The code below works but it only selects the first tr:



My HTML:



<script>if(''!='') { document.Form2.endereco_ip.value='';}</script> 
<div style="font-size: 10pt; font-weight: bold">Listagem
</div>
<hr style="height: 1px">
<table width="100%" cellpadding="2" cellspacing="1" border="1" style="border-collapse: collapse">
<tbody>
<tr style="background-color: #E8E8E8">
<td width="1%">&nbsp;
</td>
<td width="5%">
<b>Rede
</b>
</td>
<td width="5%">
<b>Tipo
</b>
</td>
<td width="5%">
<b>Portal
</b>
</td>
<td width="20%">
<b>Nome do Portal
</b>
</td>
<td width="10%">
<b>Franqueador
</b>
</td>
<td width="10%">
<b>Ambiente
</b>
</td>
<td width="10%">
<b>Endereço BD
</b>
</td>
<td width="15%">
<b>Endereço Páginas
</b>
</td>
<td width="5%">
<b>Release
</b>
</td>
<td width="5%">
<strong>Administrador</strong>
</td>
</tr>
<tr>
<td bgcolor="green" title="xxx">
</td>
<td>Nome_emp
</td>
<td>Cliente
</td>
<td>
<a target="_blank" title="Descricao." href="#">1149</a>
<td>Nome_emp
<b> - Empresa: 19;
</b>
</td>
<td>9841 - Nome - empresa
</td>
<td>Micro (95%)
</td>
<td>LINK.COM.BR
</td>
<td>
<a href="http://#" target="_blank"><font color="blue">http://#
</font></a>
</td>
<td>2.0
</td>
<td class="style1">
</td>
</tr>
</tbody>
</table>


My Selenium code:



driver.Navigate().GoToUrl("http://...");
IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));
portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
txbPortal.Text = portalweb;









share|improve this question









New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    What result does your code give you?
    – Kate Paulk
    5 hours ago










  • When I run it returns the title "Portal" being that it should return the value "1149" which is in the second tr.
    – Ronison Matos
    5 hours ago
















3














The code below works but it only selects the first tr:



My HTML:



<script>if(''!='') { document.Form2.endereco_ip.value='';}</script> 
<div style="font-size: 10pt; font-weight: bold">Listagem
</div>
<hr style="height: 1px">
<table width="100%" cellpadding="2" cellspacing="1" border="1" style="border-collapse: collapse">
<tbody>
<tr style="background-color: #E8E8E8">
<td width="1%">&nbsp;
</td>
<td width="5%">
<b>Rede
</b>
</td>
<td width="5%">
<b>Tipo
</b>
</td>
<td width="5%">
<b>Portal
</b>
</td>
<td width="20%">
<b>Nome do Portal
</b>
</td>
<td width="10%">
<b>Franqueador
</b>
</td>
<td width="10%">
<b>Ambiente
</b>
</td>
<td width="10%">
<b>Endereço BD
</b>
</td>
<td width="15%">
<b>Endereço Páginas
</b>
</td>
<td width="5%">
<b>Release
</b>
</td>
<td width="5%">
<strong>Administrador</strong>
</td>
</tr>
<tr>
<td bgcolor="green" title="xxx">
</td>
<td>Nome_emp
</td>
<td>Cliente
</td>
<td>
<a target="_blank" title="Descricao." href="#">1149</a>
<td>Nome_emp
<b> - Empresa: 19;
</b>
</td>
<td>9841 - Nome - empresa
</td>
<td>Micro (95%)
</td>
<td>LINK.COM.BR
</td>
<td>
<a href="http://#" target="_blank"><font color="blue">http://#
</font></a>
</td>
<td>2.0
</td>
<td class="style1">
</td>
</tr>
</tbody>
</table>


My Selenium code:



driver.Navigate().GoToUrl("http://...");
IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));
portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
txbPortal.Text = portalweb;









share|improve this question









New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    What result does your code give you?
    – Kate Paulk
    5 hours ago










  • When I run it returns the title "Portal" being that it should return the value "1149" which is in the second tr.
    – Ronison Matos
    5 hours ago














3












3








3







The code below works but it only selects the first tr:



My HTML:



<script>if(''!='') { document.Form2.endereco_ip.value='';}</script> 
<div style="font-size: 10pt; font-weight: bold">Listagem
</div>
<hr style="height: 1px">
<table width="100%" cellpadding="2" cellspacing="1" border="1" style="border-collapse: collapse">
<tbody>
<tr style="background-color: #E8E8E8">
<td width="1%">&nbsp;
</td>
<td width="5%">
<b>Rede
</b>
</td>
<td width="5%">
<b>Tipo
</b>
</td>
<td width="5%">
<b>Portal
</b>
</td>
<td width="20%">
<b>Nome do Portal
</b>
</td>
<td width="10%">
<b>Franqueador
</b>
</td>
<td width="10%">
<b>Ambiente
</b>
</td>
<td width="10%">
<b>Endereço BD
</b>
</td>
<td width="15%">
<b>Endereço Páginas
</b>
</td>
<td width="5%">
<b>Release
</b>
</td>
<td width="5%">
<strong>Administrador</strong>
</td>
</tr>
<tr>
<td bgcolor="green" title="xxx">
</td>
<td>Nome_emp
</td>
<td>Cliente
</td>
<td>
<a target="_blank" title="Descricao." href="#">1149</a>
<td>Nome_emp
<b> - Empresa: 19;
</b>
</td>
<td>9841 - Nome - empresa
</td>
<td>Micro (95%)
</td>
<td>LINK.COM.BR
</td>
<td>
<a href="http://#" target="_blank"><font color="blue">http://#
</font></a>
</td>
<td>2.0
</td>
<td class="style1">
</td>
</tr>
</tbody>
</table>


My Selenium code:



driver.Navigate().GoToUrl("http://...");
IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));
portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
txbPortal.Text = portalweb;









share|improve this question









New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











The code below works but it only selects the first tr:



My HTML:



<script>if(''!='') { document.Form2.endereco_ip.value='';}</script> 
<div style="font-size: 10pt; font-weight: bold">Listagem
</div>
<hr style="height: 1px">
<table width="100%" cellpadding="2" cellspacing="1" border="1" style="border-collapse: collapse">
<tbody>
<tr style="background-color: #E8E8E8">
<td width="1%">&nbsp;
</td>
<td width="5%">
<b>Rede
</b>
</td>
<td width="5%">
<b>Tipo
</b>
</td>
<td width="5%">
<b>Portal
</b>
</td>
<td width="20%">
<b>Nome do Portal
</b>
</td>
<td width="10%">
<b>Franqueador
</b>
</td>
<td width="10%">
<b>Ambiente
</b>
</td>
<td width="10%">
<b>Endereço BD
</b>
</td>
<td width="15%">
<b>Endereço Páginas
</b>
</td>
<td width="5%">
<b>Release
</b>
</td>
<td width="5%">
<strong>Administrador</strong>
</td>
</tr>
<tr>
<td bgcolor="green" title="xxx">
</td>
<td>Nome_emp
</td>
<td>Cliente
</td>
<td>
<a target="_blank" title="Descricao." href="#">1149</a>
<td>Nome_emp
<b> - Empresa: 19;
</b>
</td>
<td>9841 - Nome - empresa
</td>
<td>Micro (95%)
</td>
<td>LINK.COM.BR
</td>
<td>
<a href="http://#" target="_blank"><font color="blue">http://#
</font></a>
</td>
<td>2.0
</td>
<td class="style1">
</td>
</tr>
</tbody>
</table>


My Selenium code:



driver.Navigate().GoToUrl("http://...");
IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));
portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
txbPortal.Text = portalweb;






selenium-webdriver c# selenium-webdriver-c#






share|improve this question









New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 50 mins ago









Community

1




1






New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 5 hours ago









Ronison MatosRonison Matos

696




696




New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    What result does your code give you?
    – Kate Paulk
    5 hours ago










  • When I run it returns the title "Portal" being that it should return the value "1149" which is in the second tr.
    – Ronison Matos
    5 hours ago














  • 1




    What result does your code give you?
    – Kate Paulk
    5 hours ago










  • When I run it returns the title "Portal" being that it should return the value "1149" which is in the second tr.
    – Ronison Matos
    5 hours ago








1




1




What result does your code give you?
– Kate Paulk
5 hours ago




What result does your code give you?
– Kate Paulk
5 hours ago












When I run it returns the title "Portal" being that it should return the value "1149" which is in the second tr.
– Ronison Matos
5 hours ago




When I run it returns the title "Portal" being that it should return the value "1149" which is in the second tr.
– Ronison Matos
5 hours ago










2 Answers
2






active

oldest

votes


















5














To add explanation to what you have already figured out. The problem was that with this line you correctly acquired the second row:



IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));


but with the next piece of code, you did not get the 4th cell of the second row, but the first 4th cell of the DOM and that starts from the first row, the header. That is why it has returned "portal".



portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


so instead of the previous line you should do what you have already figured out:



portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


run the second FindElement on the second row, and not on the whole DOM again.






share|improve this answer

















  • 1




    Exactly so, thank you for the explanation. Once again I am grateful for your help.
    – Ronison Matos
    4 hours ago



















2














I made the following change and it worked:



portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;





share|improve this answer








New contributor




Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "244"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Ronison Matos is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsqa.stackexchange.com%2fquestions%2f37264%2fhow-to-select-the-second-tr-of-my-html%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    To add explanation to what you have already figured out. The problem was that with this line you correctly acquired the second row:



    IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));


    but with the next piece of code, you did not get the 4th cell of the second row, but the first 4th cell of the DOM and that starts from the first row, the header. That is why it has returned "portal".



    portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    so instead of the previous line you should do what you have already figured out:



    portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    run the second FindElement on the second row, and not on the whole DOM again.






    share|improve this answer

















    • 1




      Exactly so, thank you for the explanation. Once again I am grateful for your help.
      – Ronison Matos
      4 hours ago
















    5














    To add explanation to what you have already figured out. The problem was that with this line you correctly acquired the second row:



    IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));


    but with the next piece of code, you did not get the 4th cell of the second row, but the first 4th cell of the DOM and that starts from the first row, the header. That is why it has returned "portal".



    portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    so instead of the previous line you should do what you have already figured out:



    portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    run the second FindElement on the second row, and not on the whole DOM again.






    share|improve this answer

















    • 1




      Exactly so, thank you for the explanation. Once again I am grateful for your help.
      – Ronison Matos
      4 hours ago














    5












    5








    5






    To add explanation to what you have already figured out. The problem was that with this line you correctly acquired the second row:



    IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));


    but with the next piece of code, you did not get the 4th cell of the second row, but the first 4th cell of the DOM and that starts from the first row, the header. That is why it has returned "portal".



    portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    so instead of the previous line you should do what you have already figured out:



    portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    run the second FindElement on the second row, and not on the whole DOM again.






    share|improve this answer












    To add explanation to what you have already figured out. The problem was that with this line you correctly acquired the second row:



    IWebElement secondRow = driver.FindElement(By.CssSelector("table tr:nth-of-type(2)"));


    but with the next piece of code, you did not get the 4th cell of the second row, but the first 4th cell of the DOM and that starts from the first row, the header. That is why it has returned "portal".



    portalweb = driver.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    so instead of the previous line you should do what you have already figured out:



    portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;


    run the second FindElement on the second row, and not on the whole DOM again.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 4 hours ago









    Bence KaulicsBence Kaulics

    589216




    589216








    • 1




      Exactly so, thank you for the explanation. Once again I am grateful for your help.
      – Ronison Matos
      4 hours ago














    • 1




      Exactly so, thank you for the explanation. Once again I am grateful for your help.
      – Ronison Matos
      4 hours ago








    1




    1




    Exactly so, thank you for the explanation. Once again I am grateful for your help.
    – Ronison Matos
    4 hours ago




    Exactly so, thank you for the explanation. Once again I am grateful for your help.
    – Ronison Matos
    4 hours ago











    2














    I made the following change and it worked:



    portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;





    share|improve this answer








    New contributor




    Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      2














      I made the following change and it worked:



      portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;





      share|improve this answer








      New contributor




      Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





















        2












        2








        2






        I made the following change and it worked:



        portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;





        share|improve this answer








        New contributor




        Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        I made the following change and it worked:



        portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;






        share|improve this answer








        New contributor




        Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 5 hours ago









        Ronison MatosRonison Matos

        696




        696




        New contributor




        Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Ronison Matos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






















            Ronison Matos is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Ronison Matos is a new contributor. Be nice, and check out our Code of Conduct.













            Ronison Matos is a new contributor. Be nice, and check out our Code of Conduct.












            Ronison Matos is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Software Quality Assurance & Testing Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsqa.stackexchange.com%2fquestions%2f37264%2fhow-to-select-the-second-tr-of-my-html%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Liste der Baudenkmale in Friedland (Mecklenburg)

            Single-Malt-Whisky

            Czorneboh