Selenium IDE - 如何在 Firefox 插件中记录 xpath
我在 Firefox 插件中的 xpath 遇到问题。我有三个文本框,第一个具有 ID=login,其余的具有动态生成的 ID。第一个可以很好地在插件中编写 //input[@id='login'] 但一旦我尝试更高级的东西,它就找不到任何东西。在阅读了大量的论坛帖子后,我尝试使用 XPather 插件来生成 xpath 代码,但长 html/css 填充的字符串也不起作用。在某些线程中,人们写“xpath=//...”,我也尝试过,但没有结果。
感谢所有可能的帮助!
//M
I'm having trouble with my xpaths in the Firefox plugin. I have three textboxes, the first one has ID=login and the rest has dynamically generated IDs. The first one works fine to write in the plugin, //input[@id='login'] but as soon as I try something more advanced, it cannot find anything. After reading plenty of forum posts, I've tried the XPather plugin to generate the xpath codes but the long html/css-filled strings don't work either. In some threads, people write "xpath=//..." and I tried that too, to no result.
Thankful for all help possible!
//M
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用的两个工具是 Firebug 和 XPath 检查器,都是 Firefox 插件。
在 Firebug 中,选择 HTML 选项卡,右键单击该元素并选择“复制 XPath”
对于 XPath 检查器,右键单击页面中的元素并选择“查看 XPath”。
您可以通过将结果粘贴到 Selenium IDE 的目标字段中然后单击“查找”按钮来检查这一点。这告诉了 Selenium 结果将会是什么(比一遍又一遍地运行测试要快得多!)
我发现你必须稍微“按摩”结果,例如
如果你转到 Google 主页并查找左上角的“图像”链接,XPath 检查器给出图像 XPath 为:
//id('gbar')/x:nobr/x:a1
这会引发错误:
[error] 定位器未找到: //id('gbar')/x:nobr/x:a1,错误 = 错误:无效的 xpath 2: //id('gbar')/x:nobr/x:a1< /a>
如果您删除 id,例如
//x:nobr/x:a1
您会注意到图像周围有一个绿色框,表明 IDE 已正确解析它。
The two tools I use are Firebug and XPath Checker, both Firefox add-ons.
In Firebug, select the HTML tab, right click on the element and select "Copy XPath"
For XPath Checker, right click on the element in the page and select "View XPath".
You can check this by pasting the result into the target field of Selenium IDE and then clicking the "Find" button. This tells what the Selenium result is going to be (much faster than having to run the test over and over!)
I've found that you have to "massage" the result somewhat e.g.
If you go to the Google home page and look for the "Images" link at the top left, the XPath Checker gives the image XPath as:
//id('gbar')/x:nobr/x:a1
This throws an error:
[error] locator not found: //id('gbar')/x:nobr/x:a1, error = Error: Invalid xpath 2: //id('gbar')/x:nobr/x:a1
If you remove the id e.g
//x:nobr/x:a1
you'll notice that the image has a green box around it showing thet the IDE has correctly parsed it.
好吧,我发现了一些新信息,它确实适用于编写“xpath=/”以及 XPather 自动生成的代码。尽管如此,xpath 非常长,并且很大程度上依赖于 HTML 标签保持不变。
有谁对编写 xpath 表达式(或 css 表达式)有更好的想法,以便在以下三个文本框元素中输入信息:
TEXTBOX 1
TEXTBOX 2
TEXTBOX 3
//M
Alright, I found some new information and it does work with writing "xpath=/" and the auto-generated codes from XPather. Although, the xpaths are very long and rely a lot on the HTML tags staying the same.
Does anyone have a better idea for xpath expressions (or css expressions) to write in order to enter information in the following three textbox elements:
TEXTBOX 1
TEXTBOX 2
TEXTBOX 3
//M