如何找出带有动态ID的ExtJS元素 [英] How to find ExtJS elements with dynamic id

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

问题描述

我与硒的工作,需要得到一个控件的ID,但ID是动态的,我不能得到它。

I am working with Selenium and need to get the ID of a control but the ID is dynamic and I can't get it.

<em id="button-1122-btnWrap">
<button id="button-1122-btnEl" class="x-btn-center" autocomplete="off" role="button" disabled="disabled" hidefocus="true" type="button" style="width: 21px; height: 21px;">
         <span id="button-1122-btnInnerEl" class="x-btn-inner" style="width: 21px; height: 21px; line-height: 21px;"> </span>
         <span id="button-1122-btnIconEl" class="x-btn-icon icon-save-invoice"></span>
</button>



数1122是动态的,也有其他的按钮具有相同的开头按钮 - ### + btnWrap

推荐答案

我已经回答像很多次的问题,你可能想看看。

I have been answering questions like for many times, you might want to have a look.

ExtJS的页面是难以测试,特别是对发现的元素。

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

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

Here are some of the tips I consider useful:


  • 请不要永远使用动态生成的ID。像(:ID按钮-1122-btnEl')

  • 永远不要使用绝对/无意义的XPath,像 // DIV [4] / DIV [3] / DIV [4] / DIV / DIV / DIV / EM /按钮

采取有意义的自动生成的部分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-网格视图.X格表')将方便。如果有多个网格,尝试对其进行索引或查找辨认祖先,如(:CSS,'#东西,有意义的.X-网格视图.X格表')

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').

充分利用按钮的文字。

例如,的这个的ExtJS例如:你可以使用XPath .//跨度[含有(@class,X-BTN-内)和文本()='发送'] 。然而,这种方法不适合于CSS选择或多语言应用程序

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

测试的最好方法是在源代码中创建有意义的类名。如果您没有访问源代码,请谈谈你的经理,对使用ExtJS的应用硒真的应该是一个开发者的工作。 ExtJS的提供 CLS tdCls 自定义类的名称,以便您可以添加 CLS:测试-btn-富'在源代码中,硒可以通过得到它(:CSS,.X-面板.testing-BTN-富')

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

注意: sircapsalot的回答不适合ExtJS的工作,因为大多数按钮都CSS选择器 EM [ID ^ ='按钮 - '] [ID $ =' - btnWrap'] ,(但不能责怪他,因为这是非常特殊的ExtJS,有些人可能不熟悉)

Note: sircapsalot's answer doesn't work for ExtJS, because most of buttons have CSS Selector em[id^='button-'][id$='-btnWrap'], (but can't blame him, as this is quite ExtJS specific, some people might not be familiar with).

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

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