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

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

问题描述

我正在测试的应用程序中的所有元素具有动态代码ID 。测试总是通过,当我重播而不刷新页面,但一旦我刷新页面,测试失败因为所有元素的Id都随机变化,硒不能匹配记录的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-位置,它适用于某些对象,但是在下拉列表和按钮的情况下,它可以工作!

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 *)中的Meathods或如何创建一个新的定位器查找器 下拉列表和按钮

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, code> // * [@类= 'SomeClass的'] / LI / UL /利[2] / UL /锂[2] /表/ tbody的/ TR / TD [2] / DIV

利用有意义的自动生成的部分ids和类名。 (所以你需要在你的例子中显示更多的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-interesting .x-grid-view .x-grid-table')。在你的情况下,(:css,'#something-interesting .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')

利用按钮的文字。

例如,这个ExtJS示例:你可以使用XPath 。// li [contains(@class,'x-boundlist-item')and text()='Rescue'] 。但是,这种方法不适用于CSS选择器或多语言应用程序。

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.

最好的测试方法是在源代码中创建有意义的类名。如果您无法访问源代码,请与您的经理联系,使用Selenium对ExtJS应用程序应该是开发人员的工作。 ExtJS为自定义类名提供 cls tdCls ,因此您可以添加 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:

  • How to find ExtJS elements with dynamic id
  • How to find unique selectors for elements on pages with ExtJS for use with Selenium?
  • How to click on elements in ExtJS using Selenium?
  • Using class names in Watir
  • how to click on checkboxes on a pop-up window which doesn't have name, label

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

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