1

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 .

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

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

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

properties of Dropdown :

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

properties of Dropdown*Choice*:

<ul>
    <li class="x-boundlist-item" role="option">Rescue</li>
</ul>
Dipen
  • 17
  • 1
  • 4
Sagar
  • 733
  • 3
  • 11
  • 16
  • 1
    You need to look at the bigger picture. You are saying the ID changes all the time, well, look at what's around it? Is there a `div` that is always above the element you want? Is the element you want always a child of a particular `span` element? Is it always the 9th `div`? Is it always the `li` that has a `text` of `Rescue`? Is that `li` always the first one? Does the `ul` of it have changing ID's? Do these elements only have changing ID's? What about other attributes? – Arran Oct 28 '13 at 10:16
  • @Arran : Yes arran, the li always has text as Rescue! how di i refer the drop down option using li? – Sagar Oct 28 '13 at 12:53
  • Are there any different methods to select an option from dropdown list.. **1.If Dropdown has only one entry** in it then what to do? please explain using example . .thanq – Sagar Oct 31 '13 at 07:15

2 Answers2

2

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:

Community
  • 1
  • 1
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
  • i am attaching the html u asked please give me a ready made webdriver java code for selecting item **"IT"** from the **"Departments"** Drop down! – Sagar Oct 30 '13 at 12:23
  • @ Yi Zeng The button which i want to refer is under a div whose html is as follows :
    – Sagar Nov 04 '14 at 07:32
1

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.

Karthikeyan
  • 2,634
  • 5
  • 30
  • 51