使用 Watir 获取该行第一个单元格中具有唯一文本的第二个表格单元格的值
我想获取表行的第二个单元格中的值,其中唯一值位于第一个单元格中。第二个单元格的值不断变化。
<table class="mm-table" cellspacing="0" cellpadding="3" border="0">
<tr class="trhover" onclick="location.href='stock.php?id=RI&p=wtch';">
<td align="left" rowspan="1" class="tdwidth35per paddingleft4px">
<a shape="rect" href="stock.php?id=RI&p=wtch"> Reliance </a></td>
<td align="right" rowspan="1" class="tdwidth35per"> **951.35** </td>
<td align="right" rowspan="1" class="tdwidth30per"><font color="#008000">0.60</font></td>
</tr>
上面是表格。还有其他同名的表。我想访问包含文本“951.35”的第二个单元格
I want to get the value in the second cell of a row of a table, where a unique value is in the first cell. The value of the second cell keeps on changing.
<table class="mm-table" cellspacing="0" cellpadding="3" border="0">
<tr class="trhover" onclick="location.href='stock.php?id=RI&p=wtch';">
<td align="left" rowspan="1" class="tdwidth35per paddingleft4px">
<a shape="rect" href="stock.php?id=RI&p=wtch"> Reliance </a></td>
<td align="right" rowspan="1" class="tdwidth35per"> **951.35** </td>
<td align="right" rowspan="1" class="tdwidth30per"><font color="#008000">0.60</font></td>
</tr>
Above is the table. There are other tables with the same name. I want to access the second cell which contains the text "951.35"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这是否会导致您想要的单元格闪烁
,或者如果您只知道该单元格中的文本的一部分,请尝试此操作。
如果由于某种原因使用 .parent 不起作用,您也可以尝试匹配文本的一部分整行上的文本
请注意,对于使用基于零的索引的 firewater,我相信您需要将索引值更改为 1
另请注意,这仅在页面上只有一个包含指定文本的单元格时才有效,特别是在最后两个使用正则表达式来匹配所需文本的示例中。在这种情况下,如果另一个单元格包含这些数字,即使它是另一个值(例如 12951.356)的一部分,Watir 也不会知道您想要匹配哪个值,并且会给您一个错误。
如果其中任何一个可以闪烁您想要的单元格,则只需将 .flash 替换为 .text 即可获取单元格中的文本值。
See if this causes the cell you want to flash
or if you only know a part of the text that will be in that cell, try this
If for some reason using .parent won't work you can also just try matchng a portion of the text on the entire row
Note that in the case of firewater which uses zero based indexing I believe you would need to change the index value to 1
Also note that this would only work if there is only a single cell on the page with the specified text, especially in the case of the last two examples that are using a regular expression to match the text you want. In that case if there is another cell with those numbers, even if it's part of another value such as 12951.356 Watir would not know which one you wanted to match, and would give you an error.
If any of those work to flash the cell you want, then just replace .flash with .text to get the text value in the cell.
尝试这样的事情:
Try something like this: