如何查找具有动态 ID 的 ExtJS 元素的 XPath [英] How to find XPath of an ExtJS element with dynamic ID

查看:19
本文介绍了如何查找具有动态 ID 的 ExtJS 元素的 XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试的应用程序中的所有 元素 都具有 动态 ID .当我重播它不刷新页面时,测试总是通过,但是一旦我刷新页面,测试失败 因为所有元素的 Id 都是随机变化的,而 selenium 无法匹配记录的 id 与新的

All the elements in the application which i am testing have dynanic ID's . The test always passes when i replay it without refreshing the page but as soon as i refresh the page, The Test Fails because Id's of all the elements changes randomly and selenium cannot match the recorded id's with the new ones .

我尝试使用 Xpath-position,它适用于某些对象,但在下拉列表和按钮的情况下,它不起作用!

I tried to use Xpath-position, It works for some objects but in case of Dropdown list and Buttons, it dosent work!

谁能告诉我如何找到对象的 Xpath(JAVA 或 S*elence* 中的方法)或如何为下拉列表和按钮

Can anyone please tell me how to find the Xpath (Meathods in JAVA or S*elence*) of an object OR How to create a new Locator Finder for Dropdown list and Buttons

我可以显示取笑我的下拉列表的属性(由 Firebug 检测).

I can show the properties (Inspected by Firebug) of the dropdown which is teasing me.

下拉菜单的属性:

<div id="ext-gen1345" class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-last x-unselectable" role="button" style="-moz-user-select: none;"></div>

下拉菜单的属性*选择*:

<ul>
    <li class="x-boundlist-item" role="option">Rescue</li>
</ul>

推荐答案

发帖前请先搜索一下,这个问题我一直在反复回答.

Please search before posting, I have been answering this over and over.

ExtJS 页面很难测试,尤其是在查找元素方面.

ExtJS pages are hard to test, especially on finding elements.

以下是我认为有用的一些提示:

Here are some of the tips I consider useful:

  • 永远不要使用动态生成的 ID.像 (:id, 'ext-gen1345')
  • 永远不要使用绝对/无意义的XPath,比如//*[@class='someclass']/li/ul/li[2]/ul/li[2]/table/tbody/tr/td[2]/div

利用有意义的自动生成的部分 ID 和类名.(因此您需要在示例中显示更多 HTML,因为我可以提出建议.)

Take advantage of meaningful auto-generated partial ids and class names. (So you need show more HTML in your example, as I can make suggestions.)

例如,这个 ExtJS 网格示例:(:css, '.x-grid-view .x-grid-table') 会很方便.如果有多个网格,请尝试索引它们或定位可识别的祖先,例如 (:css, '#something-meaningful .x-grid-view .x-grid-table').在你的情况下,(:css, '#something-meaningful .x-form-arrow-trigger')

For example, this ExtJS grid example: (:css, '.x-grid-view .x-grid-table') would be handy. If there are multiple of grids, try index them or locate the identifiable ancestor, like (:css, '#something-meaningful .x-grid-view .x-grid-table'). In your case, (:css, '#something-meaningful .x-form-arrow-trigger')

利用按钮的文本.

例如,this ExtJS 示例:您可以使用 XPath .//li[contains(@class, 'x-boundlist-item') 和 text()='Rescue'].但是,这种方法不适用于 CSS Selector 或多语言应用程序.

For example, this ExtJS example: you can use XPath .//li[contains(@class, 'x-boundlist-item') and text()='Rescue']. However, this method is not suitable for CSS Selector or multi-language applications.

最好的测试方法是在源代码中创建有意义的类名.如果您无权访问源代码,请与您的经理交谈,对 ExtJS 应用程序使用 Selenium 确实应该是开发人员的工作.ExtJS 为自定义类名提供了 clstdCls,所以你可以在你的源代码中添加 cls:'testing-btn-foo',并且Selenium 可以通过 (:css, '.x-panel .testing-btn-foo') 获取.

The best way to test is to create meaningful class names in the source code. If you don't have the access to the source code, please talk to your manager, using Selenium against ExtJS application should really be a developer's job. ExtJS provides cls and tdCls for custom class names, so you can add cls:'testing-btn-foo' in your source code, and Selenium can get it by (:css, '.x-panel .testing-btn-foo').

我对这个主题的其他回答:

Other answers I made on this topic:

这篇关于如何查找具有动态 ID 的 ExtJS 元素的 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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