gpt4 book ai didi

java - 如何在selenium java中通过断言验证动态表

转载 作者:行者123 更新时间:2023-12-01 20:18:14 24 4
gpt4 key购买 nike

我已经尝试过像这样一一原始

String element= driver.findElement(By.xpath("//*[@id='historyRow']/tbody/tr[1]/td[1]")).getText();

Assert.assertEquals(element, auto);

这是 HTML 代码:

I want to verify that Add a second value in table and verify that all details are displayed for each value with previous value added first. How to verify for all raw Is there any other way rather than one by one

<table id="historyRow">
<thead>
<tr style="cursor: pointer;">
<th class="portlet-section-header descending">
<a href="https://www.uat-office.com/customer/portal/_ns:YWNtLVZpZXdQb2xpdGljYWxEb25hdGlvbi0xX19jbS1WaWV3UG9saXRpY2FsRG9uYXRpb24tMnxjMHxkMXxlZC0yNTA3NTgwLXM9MT0wfGVkLTI1MDc1ODAtcD0xPTF8ZWFjdGlvbj0xPXZpZXdIaXN0b3J5fGVkLTI1MDc1ODAtbz0xPTJ8ZWlkPTE9NGZkMjQyZjY2ZTgyYWY5NTAxNmU4NDE0ZDcyMjE2NmM_/Management/ViewPoliticalDonation.psml" style="text-decoration: none;">Date and Time</a></th>
<th class="portlet-section-header">
<a href="https://www.uat-office.com/customer/portal/_ns:YWNtLVZpZXdQb2xpdGljYWxEb25hdGlvbi0xX19jbS1WaWV3UG9saXRpY2FsRG9uYXRpb24tMnxjMHxkMXxlZC0yNTA3NTgwLXM9MT0xfGVkLTI1MDc1ODAtcD0xPTF8ZWFjdGlvbj0xPXZpZXdIaXN0b3J5fGVkLTI1MDc1ODAtbz0xPTJ8ZWlkPTE9NGZkMjQyZjY2ZTgyYWY5NTAxNmU4NDE0ZDcyMjE2NmM_/Management/ViewPoliticalDonation.psml">User</a></th>
<th class="portlet-section-header">
<a href="https://www.office.com/customer/portal/_ns:YWNtLVZpZXdQb2xpdGljYWxEb25hdGlvbi0xX19jbS1WaWV3UG9saXRpY2FsRG9uYXRpb24tMnxjMHxkMXxlZC0yNTA3NTgwLXM9MT0yfGVkLTI1MDc1ODAtcD0xPTF8ZWFjdGlvbj0xPXZpZXdIaXN0b3J5fGVkLTI1MDc1ODAtbz0xPTJ8ZWlkPTE9NGZkMjQyZjY2ZTgyYWY5NTAxNmU4NDE0ZDcyMjE2NmM_/Management/ViewPoliticalDonation.psml">Action</a></th>
<th class="portlet-section-header">
<a href="https://www.uat-office.com/customer/portal/_ns:YWNtLVZpZXdQb2xpdGljYWxEb25hdGlvbi0xX19jbS1WaWV3UG9saXRpY2FsRG9uYXRpb24tMnxjMHxkMXxlZC0yNTA3NTgwLXM9MT0zfGVkLTI1MDc1ODAtcD0xPTF8ZWFjdGlvbj0xPXZpZXdIaXN0b3J5fGVkLTI1MDc1ODAtbz0xPTJ8ZWlkPTE9NGZkMjQyZjY2ZTgyYWY5NTAxNmU4NDE0ZDcyMjE2NmM_/eManagement/ViewPoliticalDonation.psml">Description / Comment</a></th></tr></thead>
<tbody>
<tr class="portlet-section-body" style="cursor: pointer;">
<td>
Nov 19, 2019 09:34:10 AM EST
</td>
<td>
<!-- This hack is needed just for requests which had this audit comment inserted by their rule execution -->
<!-- New requests won't have this comment anymore -->


abc,auto

</td>
<td>

Edit

</td>
<td>





<table style="width: auto;">


<tbody><tr style="cursor: pointer;"><td align="left" style="border-spacing:1px; padding-top:0px; padding-right:3px; padding-bottom:0px; padding-left:0px;">
<table style="border-spacing:1px; padding-top:0px; padding-right:3px; padding-bottom:0px; padding-left:0px; width: auto;">
<tbody><tr style="cursor: pointer;">
<td align="left" style="border-spacing:1px; padding-top:0px; padding-right:3px; padding-bottom:0px; padding-left:0px; vertical-align:text-top; text-align:left;">
<b>Comment</b>
</td>
<td style="border-spacing:1px; padding-top:0px; padding-right:3px; padding-bottom:0px; padding-left:0px;">
Add Comment. comment
</td>
</tr>
</tbody></table>

最佳答案

尝试下面的代码:请检查大括号的闭合情况。

        // Grab the table 
WebElement table = driver.findElement(By.id("View"));
//get the size of the list of the rows
List<WebElement> totalRows = table.findElements(By.tagName("tr"));
int rows_count = totalRows.size();
//Loop will execute till the last row of table.
for (int row=0; row<rows_count; row++){
//To locate columns(cells) of that specific row.
List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns(cells) In that specific row.
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row "+row+" are "+columns_count);

//Loop will execute till the last cell of that specific row.
for (int column=0; column<columns_count; column++){
//To retrieve text from that specific cell.
String celtext = Columns_row.get(column).getText();
System.out.println("Cell Value Of row number "+row+" and column number "+column+" Is "+celtext);
}
});

关于java - 如何在selenium java中通过断言验证动态表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58949080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com