Xpath匹配一个节点但在Webdriver中不起作用 [英] Xpath matching one node but not working in webdriver

查看:118
本文介绍了Xpath匹配一个节点但在Webdriver中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firepath中正确验证并匹配1个节点的XPath在Selenium Webdriver(java)中无法正常工作是否正常?我有一个动态元素,并且已经使用"contains"方法生成了一个XPath,该XPath匹配了一个节点,该节点恰好与我正在寻找的相同元素.在Eclipse中,Webdriver抛出"NoSuchElementException",因为它找不到元素.当您认为自己已经掌握了Xpath的技巧之后,一些顽固的网络元素便会发现您的缺陷.

Is it normal for an XPath that was validated correctly in firepath and matched 1 node to fail to work in selenium webdriver (java)? I have a dynamic element and I have generated an XPath using the "contains" method which matched a single node that happens to be the same element I was looking for. In eclipse, webdriver throws a "NoSuchElementException" as it was unable to find the element. After you think you have mastered the tricks behind Xpath, some stubborn webelements uncover your flaws.

对于所附的html,我生成了以下Xpath.任何人都可以帮助生成可以使用的XPath甚至CSS吗?

For the attached html, I have generated the below Xpath. Can anyone help generate an XPath or even CSS that would work?

//div[contains(@id, 'gwt-uid') and @aria-selected='true']

推荐答案

是.始终有可能使用Firebug进行XPATH匹配(在开发模式下,您手动访问页面)在运行期间可能无法识别(使用硒启动的浏览器).不是因为Firebug显示错误,而是XPATH使用的HTML可能不相同(可能已更改,可能是微妙的更改).

Yes. There is always a possibility of XPATH matching using Firebug (during development mode, where you visited page manually) may not identify during run time (browser launched using selenium). It is not because of Firebug showing wrong, but the HTML against which XPATH is using, may not be the same (might have changed, may be subtle changes).

我强烈建议在运行时暂停(不停止执行)(一种方法是,使用Thread.sleep(100)(100秒))给您足够的时间来执行再次评估您的XPATH以查看匹配项.发表您的观察结果.

I would strongly suggest pause (not stopping it) the execution during the run-time (one way is, using Thread.sleep(100) (100 seconds)) to give you enough time to evaluate your XPATH again to see the matches. post your observations.

XPATH对我来说似乎很好.

XPATH seems fine to me.

可疑,aria-selected设置为false

这篇关于Xpath匹配一个节点但在Webdriver中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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