我是靠谱客的博主 清秀哈密瓜,最近开发中收集的这篇文章主要介绍java+selenium获取整个表格的内容,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

为什么80%的码农都做不了架构师?>>>   hot3.png

被测试的表格HTML片段代码:

<table class="datagrid-btable" cellspacing="0" cellpadding="0" border="0">
<tbody><tr id="datagrid-row-r6-2-0" datagrid-row-index="0" class="datagrid-row">
<td field="id">
<div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-id">4336441FAEE82944E0537AAF190A216C</div>
</td>
<td field="name"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-name">planA</div></td>
<td field="homepageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBack">显示</div></td>
<td field="homepageBanner"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBanner">隐藏</div></td>
<td field="minimalistEndpage"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-minimalistEndpage">否</div></td>
<td field="showAnyDoor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-showAnyDoor">隐藏</div></td>
<td field="recommendReadonly"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendReadonly">只读</div></td>
<td field="recommendSetup"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendSetup">隐藏</div></td>
<td field="onePersonMoreAccount"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-onePersonMoreAccount">支持</div></td>
<td field="uploadImageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-uploadImageBack">显示</div></td>
<td field="accountResultBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-accountResultBack">显示</div></td>
<td field="skinColor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-skinColor">5d6bc3</div></td>
<td field="descriptor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-descriptor">金融平台渠道SDK</div></td></tr>
<tr id="datagrid-row-r6-2-1" datagrid-row-index="1" class="datagrid-row datagrid-row-alt">
<td field="id"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-id">4336441FAEE92944E0537AAF190A216C</div></td>
<td field="name"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-name">planB</div></td>
<td field="homepageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBack">隐藏</div></td>
<td field="homepageBanner"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBanner">隐藏</div></td>
<td field="minimalistEndpage"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-minimalistEndpage">否</div></td>
<td field="showAnyDoor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-showAnyDoor">隐藏</div></td>
<td field="recommendReadonly"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendReadonly">可编辑</div></td>
<td field="recommendSetup"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendSetup">隐藏</div></td>
<td field="onePersonMoreAccount"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-onePersonMoreAccount">支持</div></td>
<td field="uploadImageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-uploadImageBack">隐藏</div></td>
<td field="accountResultBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-accountResultBack">隐藏</div></td>
<td field="skinColor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-skinColor">5d6bc3</div></td>
<td field="descriptor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-descriptor">银行(支持一人多户)</div></td></tr>
<tr id="datagrid-row-r6-2-2" datagrid-row-index="2" class="datagrid-row">
<td field="id"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-id">4336441FAEEA2944E0537AAF190A216C</div></td>
<td field="name"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-name">planC</div></td>
<td field="homepageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBack">隐藏</div></td>
<td field="homepageBanner"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBanner">隐藏</div></td>
<td field="minimalistEndpage"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-minimalistEndpage">否</div></td>
<td field="showAnyDoor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-showAnyDoor">隐藏</div></td>
<td field="recommendReadonly"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendReadonly">只读</div></td>
<td field="recommendSetup"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendSetup">隐藏</div></td>
<td field="onePersonMoreAccount"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-onePersonMoreAccount">不支持</div></td>
<td field="uploadImageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-uploadImageBack">隐藏</div></td>
<td field="accountResultBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-accountResultBack">隐藏</div></td>
<td field="skinColor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-skinColor">5d6bc3</div></td>
<td field="descriptor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-descriptor">银行(不支持一人多户)</div></td></tr>
<tr id="datagrid-row-r6-2-3" datagrid-row-index="3" class="datagrid-row datagrid-row-alt">
<td field="id"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-id">4336441FAEEB2944E0537AAF190A216C</div></td>
<td field="name"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-name">planD</div></td>
<td field="homepageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBack">显示</div></td>
<td field="homepageBanner"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBanner">显示</div></td>
<td field="minimalistEndpage"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-minimalistEndpage">否</div></td>
<td field="showAnyDoor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-showAnyDoor">隐藏</div></td>
<td field="recommendReadonly"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendReadonly">只读</div></td>
<td field="recommendSetup"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendSetup">显示</div></td>
<td field="onePersonMoreAccount"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-onePersonMoreAccount">支持</div></td>
<td field="uploadImageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-uploadImageBack">显示</div></td>
<td field="accountResultBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-accountResultBack">显示</div></td>
<td field="skinColor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-skinColor">af292c</div></td>
<td field="descriptor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-descriptor">针对交易</div></td></tr>
<tr id="datagrid-row-r6-2-4" datagrid-row-index="4" class="datagrid-row"><td field="id"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-id">4336441FAEEC2944E0537AAF190A216C</div></td>
<td field="name"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-name">planE</div></td>
<td field="homepageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBack">隐藏</div></td>
<td field="homepageBanner"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-homepageBanner">隐藏</div></td>
<td field="minimalistEndpage"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-minimalistEndpage">否</div></td>
<td field="showAnyDoor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-showAnyDoor">隐藏</div></td>
<td field="recommendReadonly"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendReadonly">只读</div></td>
<td field="recommendSetup"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-recommendSetup">隐藏</div></td>
<td field="onePersonMoreAccount"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-onePersonMoreAccount">支持</div></td>
<td field="uploadImageBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-uploadImageBack">隐藏</div></td>
<td field="accountResultBack"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-accountResultBack">隐藏</div></td>
<td field="skinColor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-skinColor">5d6bc3</div></td>
<td field="descriptor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-descriptor">金融平台渠道App</div></td></tr>
<td field="skinColor"><div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-skinColor">5d6bc3</div></td>
<div style="text-align:center;height:auto;" class="datagrid-cell datagrid-cell-c6-descriptor">常规开户</div></td></tr></tbody></table>

 

java代码:

	public static void getRangeFromRows(WebDriver driver){
WebElement table= driver.findElement(By.xpath("//*[@id='product_mgt_wrap']/div[1]/div[2]/div[2]/div[2]/div[2]/table"));
List<WebElement> rows = table.findElements(By.tagName("tr"));
for(WebElement row:rows){
List<WebElement> col = row.findElements(By.tagName("td"));
for(WebElement cell:col){
System.out.print(cell.getText() + "t");
}
System.out.print("nt");
}
}

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://my.oschina.net/bysu/blog/829336

最后

以上就是清秀哈密瓜为你收集整理的java+selenium获取整个表格的内容的全部内容,希望文章能够帮你解决java+selenium获取整个表格的内容所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部