根据列获取特定值 &来自动态 Web 表的行名称,其中的列和行位置也是动态的 [英] Get specific value based on column & row name from dynamic Web table in which columns & rows position also dynamic

查看:25
本文介绍了根据列获取特定值 &来自动态 Web 表的行名称,其中的列和行位置也是动态的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须根据列名和行名打印特定值.问题是列位置和行位置每次都改变.表数据是动态的,值在不断变化.所有值都不是恒定的和 xpath 从表 2 中获取Ap​​ril/2001"的值.

//table[@id='table2']//td[position()=count(//th[normalize-space(.)='Month/Year']/preceding-sibling::th)+1 和 normalize-space(.)='April']/ancestor::tr//td[position()=count(//table[@id='table2']//th[normalize-space(.)='2001']/preceding-sibling::th)+1]

上面 2 个 xpath 之间的唯一区别是表 id **//table[@id='tableX**.请根据您的应用程序值更新表定位器.如果这有帮助,请告诉我.

I have to print a specific value based on column and row names. Bt the problem is that columns position and rows position changes every time. And table data is dynamic, values are changing continuously. All the values are not constantmy dynamic web table is. and i want specific value of month April in year 2001.

解决方案

Here is the sample table based on the attached screenshot.

<html>
	<table id='table1' border=" 1px solid black">
	<tr>		
		<th>Month/Year</th>
		<th>2003</th>
		<th>2004</th>
		<th>2001</th>
		<th>2005</th>
		<th>2002</th>
	</tr>	
	<tr> 
		<td>May</td>
		<td>122</td>
		<td>84</td>
		<td>7777</td>
		<td>12</td>
		<td>122</td>
	</tr>

	<tr> 
		<td>Feb</td>
		<td>45</td>
		<td>445</td>
		<td>565</td>
		<td>222</td>
		<td>122</td>
	</tr>
	<tr> 
		<td>April</td>
		<td>3556</td>
		<td>212</td>
		<td>21</td>
		<td>1546</td>
		<td>855</td>
	</tr>
	</table>
	<span>-----------------------------------------------</span>
	<table id='table2' border=" 1px solid black">
	<tr>		
		<th>Month/Year</th>
		<th>2002</th>
		<th>2001</th>
		<th>2003</th>
		<th>2004</th>
		<th>2005</th>
	</tr>	
	<tr> 
		<td>April</td>
		<td>120</td>
		<td>243</td>
		<td>221</td>
		<td>21</td>
		<td>65</td>
	</tr>

	<tr> 
		<td>May</td>
		<td>96</td>
		<td>146</td>
		<td>454</td>
		<td>452</td>
		<td>4566</td>
	</tr>
	<tr> 
		<td>March</td>
		<td>788</td>
		<td>139</td>
		<td>10</td>
		<td>1001</td>
		<td>013</td>
	</tr>
	<tr> 
		<td>Feb</td>
		<td>552</td>
		<td>1245</td>
		<td>545</td>
		<td>41</td>
		<td>41</td>
	</tr>
	</table>
</html>

Below is the xpath to get the value of "April/2001" from table 1.

//table[@id='table1']//td[position()=count(//th[normalize-space(.)='Month/Year']/preceding-sibling::th)+1 and normalize-space(.)='April']/ancestor::tr//td[position()=count(//table[@id='table1']//th[normalize-space(.)='2001']/preceding-sibling::th)+1]

And xpath to get the value of "April/2001" from table 2.

//table[@id='table2']//td[position()=count(//th[normalize-space(.)='Month/Year']/preceding-sibling::th)+1 and normalize-space(.)='April']/ancestor::tr//td[position()=count(//table[@id='table2']//th[normalize-space(.)='2001']/preceding-sibling::th)+1]

The only difference between the 2 xpaths' above is table id **//table[@id='tableX**. Please update the table locator as per your application values. Let me know if this is helpful.

这篇关于根据列获取特定值 &amp;来自动态 Web 表的行名称,其中的列和行位置也是动态的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆