How to find XPath of an ExtJS element with dynamic ID

无人久伴 提交于 2019-12-03 22:48:40
Yi Zeng

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

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

Here are some of the tips I consider useful:

  • Don't ever use dynamically generated IDs. like (:id, 'ext-gen1345')
  • Don't ever use absolute/meaningless XPath, like //*[@class='someclass']/li/ul/li[2]/ul/li[2]/table/tbody/tr/td[2]/div

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

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

  • Take advantage of button's text.

    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.

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

I would suggest you build a xpath from any of the parent of your DIV. you may get messed if there is no immediate parent node has such one.

example,

//*[@id='parentof div']/div
//*[@class='grand parent of div']/div/div

i did even something like this,

//*[@class='someclass']/li/ul/li[2]/ul/li[2]/table/tbody/tr/td[2]/div

But still, its not encouraged to do so.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!