Watir-webdriver:Firefox 未单击正确的链接,但 IE 和 Chrome 工作正常
问题帮助
嗨,我是 Ruby 和 watir-webdriver 的新手,我已经搜索遍了,但找不到答案。
我有一个位于表格内的链接,该表格在表格顶部有一个标题,如果单击该标题,则可以对表格进行数字排序。在 Chrome 和 Ie 中,链接可以正常单击并继续,但在 Firefox 中,它会单击标题并重新组织表格,但不会单击链接,并且不会给出任何错误消息。
我尝试过 xpath、regexp、表引用、:href、:text(没有 id 或名称字段),并使用 .flash 方法,我发现它查看了正确的链接,但仍然单击顶部表的。
这是 html
<thead>
<tr>
<th id="0" class="canclick" width="14%" align="left" datatype="string">
Contract #
<span id="sortIndicatorBlank"> </span>
</th>
</tr>
</thead>
<tbody>
<tr class="backD">
<td width="10%" valign="top" align="left">
<a href="/policy/clientAccountSummary.action?forwarder=ClientList&basho.menuNodeId=12801&basho.taskPanelNodeId=1261&number=015633828"> 015633828 </a>
</td>
这是我正在使用的代码,它在 Chrome 和 Ie 中单击正确的链接,但在 Firefox 中不单击
link = "015633828"
exp1 = Regexp.new link
@browser.link(:href, exp1).click
再次澄清:使用 .flash 方法它找到正确的链接(闪烁我要在表格内单击的链接) ,但在实际的 .click 操作中,它单击标题的“Contract #”部分而不是链接。
我认为问题可能是表格标题是一个浮动标题,即当您向下滚动页面时它会随着您移动并停留在页面顶部,以便它始终可见。
如果您需要更多信息来澄清,请告诉我。谢谢!
Question help
Hi I'm new to Ruby and watir-webdriver and I've searched all over and can't find an answer to this.
I have a link that is inside a table, this table has a header on top of the table that sorts the table numerically if clicked. In Chrome and Ie, the link is clicked fine and continues on but in firefox it clicks the header and reorganizes the table, but not the link and no error message is given.
I've tried xpath, regexp, table referencing, :href, :text, (there are no id or name fields), and using the .flash method I've seen that it looks at the correct link, but still clicks the top of the table.
Here is the html
<thead>
<tr>
<th id="0" class="canclick" width="14%" align="left" datatype="string">
Contract #
<span id="sortIndicatorBlank"> </span>
</th>
</tr>
</thead>
<tbody>
<tr class="backD">
<td width="10%" valign="top" align="left">
<a href="/policy/clientAccountSummary.action?forwarder=ClientList&basho.menuNodeId=12801&basho.taskPanelNodeId=1261&number=015633828"> 015633828 </a>
</td>
Here is the code I'm using that clicks the correct link in Chrome and Ie but not in firefox
link = "015633828"
exp1 = Regexp.new link
@browser.link(:href, exp1).click
Again to clarify: Using .flash method it finds the correct link(flashes the link I want to click inside the table), but on the actual .click operation it clicks the "Contract #" portion of the header not the link.
I think the problem might be that the table header, is a floating header, ie it moves with you as you scroll down the page and stays at the top of the page so that its always visible.
If you need more info to clarify let me know. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定它为什么这样做,但作为一种潜在的解决方法,您是否可以尝试按照以下方式将 href 值从链接中提取出来,然后让浏览器直接转到它?
(您可能需要将网站的基本 url 添加到 href 才能使其正常工作,但您明白了)
I'm not sure why it is doing this, but as a potential workaround could you perhaps try something along the following lines to pull the href value out of the link and then have the browser goto it directly?
(you might need to add the base url for the site to the href to make that work, but you get the idea)
或者尝试使用 xpath:
@browser.link(:xpath,"//a[@text='someUser#']").click
or possibly try with xpath:
@browser.link(:xpath,"//a[@text='someUser#']").click
好吧,如果您想确保单击
td
标记内的链接,而不是th
标记内的链接,请尝试以下操作:您提供的这是一件好事HTML 和 Watir 代码,但在未来,尝试提供真正的 HTML(或尽可能真实)。
someUser#
真的让我很困惑,我什至不确定我是否理解了这个问题。如果我提供的解决方案不起作用,请编辑问题以包含真实的 HTML。
Well, if you want to make sure a link inside
td
tag is clicked, and not a link insideth
tag, try this:It is a good thing that you have provided both HTML and Watir code, but in the future, try to provide real HTML (or as real as possible).
someUser#
really confused me, I am not even sure I understood the problem.If the solution I have provided does not work, please edit the question to contain real HTML.