Selenium IDE - 如何在 Firefox 插件中记录 xpath

发布于 2024-09-07 21:32:18 字数 264 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[浮城] 2024-09-14 21:32:18

我使用的两个工具是 FirebugXPath 检查器,都是 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.

久隐师 2024-09-14 21:32:18

好吧,我发现了一些新信息,它确实适用于编写“xpath=/”以及 XPather 自动生成的代码。尽管如此,xpath 非常长,并且很大程度上依赖于 HTML 标签保持不变。

有谁对编写 xpath 表达式(或 css 表达式)有更好的想法,以便在以下三个文本框元素中输入信息:

TEXTBOX 1

  • Firebug:输入类型=“文本”tabindex=“110”
    名称=“6011300f91d9f186d1b7ab1a034827da”
    id=“输入1”
  • Selenium 中的工作 xpath,从 XPather 检索:
    xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content']/div [@id='contentPadding']/div[1]/fieldset[1]/input[@id='input1']

TEXTBOX 2

  • 输入类型=“密码”tabindex=“110”
    名称=“0de4766295b7a965fc4969da3df6824ba”
  • xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content' ]/div[@id='contentPadding']/div[1]/fieldset[2]/input

TEXTBOX 3

  • 输入类型=“password”tabindex=“110”class=“last”name=“6c4e0fcde65e258c3dc7c508a1cc666a”
  • xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content' ]/div[@id='contentPadding']/div[1]/fieldset[3]/input

//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

  • Firebug: input type="text" tabindex="110"
    name="6011300f91d9f186d1b7ab1a034827da"
    id="input1"
  • Working xpath in Selenium, retrieved from XPather:
    xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content']/div[@id='contentPadding']/div[1]/fieldset[1]/input[@id='input1']

TEXTBOX 2

  • input type="password" tabindex="110"
    name="0de4766295b7a965fc4969da3df6824ba"
  • xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content']/div[@id='contentPadding']/div[1]/fieldset[2]/input

TEXTBOX 3

  • input type="password" tabindex="110" class="last" name="6c4e0fcde65e258c3dc7c508a1cc666a"
  • xpath=/html/body[@id='fire']/form[@id='loginForm']/div/div/div[@id='container']/div[@id='content']/div[@id='contentPadding']/div[1]/fieldset[3]/input

//M

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文