How to select the second tr of my HTML?
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%">
</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#
New contributor
add a comment |
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%">
</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#
New contributor
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
add a comment |
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%">
</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#
New contributor
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%">
</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#
selenium-webdriver c# selenium-webdriver-c#
New contributor
New contributor
edited 50 mins ago
Community♦
1
1
New contributor
asked 5 hours ago
Ronison MatosRonison Matos
696
696
New contributor
New contributor
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
1
Exactly so, thank you for the explanation. Once again I am grateful for your help.
– Ronison Matos
4 hours ago
add a comment |
I made the following change and it worked:
portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
New contributor
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
1
Exactly so, thank you for the explanation. Once again I am grateful for your help.
– Ronison Matos
4 hours ago
add a comment |
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.
1
Exactly so, thank you for the explanation. Once again I am grateful for your help.
– Ronison Matos
4 hours ago
add a comment |
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.
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.
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
add a comment |
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
add a comment |
I made the following change and it worked:
portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
New contributor
add a comment |
I made the following change and it worked:
portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
New contributor
add a comment |
I made the following change and it worked:
portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
New contributor
I made the following change and it worked:
portalweb = secondRow.FindElement(By.CssSelector("td:nth-of-type(4)")).Text;
New contributor
New contributor
answered 5 hours ago
Ronison MatosRonison Matos
696
696
New contributor
New contributor
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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