2

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

4

2 回答 2

3

我使用的两个工具是FirebugXPath Checker,它们都是 Firefox 附加组件。

在 Firebug 中,选择 HTML 选项卡,右键单击元素并选择“复制 XPath”

对于 XPath Checker,右键单击页面中的元素并选择“View XPath”。

您可以通过将结果粘贴到 Selenium IDE 的目标字段中然后单击“查找”按钮来检查这一点。这告诉 Selenium 结果将是什么(比一遍又一遍地运行测试要快得多!)

我发现你必须在某种程度上“按摩”结果,例如

如果您访问 Google 主页并在左上角查找“图像”链接,XPath 检查器将图像 XPath 显示为:

//id('gbar')/x:nobr/x:a 1

这会引发错误:

[错误] 定位器未找到://id('gbar')/x:nobr/x:a 1,错误 = 错误:无效 xpath 2://id('gbar')/x:nobr/x:a 1

如果您删除 id 例如

//x:nobr/x:a 1

您会注意到图像周围有一个绿色框,显示 IDE 已正确解析它。

于 2010-09-15T01:19:59.793 回答
0

好吧,我找到了一些新信息,它确实适用于编写“xpath=/”和 XPather 自动生成的代码。虽然,xpath 很长,并且很大程度上依赖于 HTML 标记保持不变。

有没有人更好地编写 xpath 表达式(或 css 表达式)以便在以下三个文本框元素中输入信息:

文本框 1

  • 萤火虫:输入类型="文本" tabindex="110" 名称="6011300f91d9f186d1b7ab1a034827da" id="input1"
  • 在 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']

文本框 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

文本框 3

  • 输入类型="密码" 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

于 2010-07-01T08:22:57.970 回答