0
<td id="ext-gen383" class="x-toolbar-cell">
    <table id="ext-comp-1144" class="x-btn x-btn-icon" cellspacing="0">
    <tbody class="x-btn-small x-btn-icon-small-left">
    <tr>
     <tr>
     <td class="x-btn-ml">
     <td class="x-btn-mc">
     <em class=" x-unselectable" unselectable="on">
     **<button id="ext-gen384" class="x-btn-text x-tbar-page-last" type="button">**      </button>
</em>

I tried to click the button. Please see the html above. Tried so many ways. eg:

//*[contains(@class,'x-btn-text x-tbar-page-last')] or
//button[contains(@class,'x-btn-text x-tbar-page-last')]

But still not working.

  • Automating ExtJS applications is difficult. It is hard to show you in a relatively short paragraph. Here are few answers I made previsouly, feel free to have a look [here](http://stackoverflow.com/a/19668866/1177636), [here](http://stackoverflow.com/a/18047730/1177636), [here](http://stackoverflow.com/a/19531840/1177636) and [here](http://stackoverflow.com/a/19149454/1177636). The HTML you have provided is not enough to give you a good answer, even if you have posted whole HTML, there might not be a good way to locate this button. If possible, please add unique class names to source code. – Yi Zeng May 22 '14 at 21:46

2 Answers2

0

Its hard to tell without seeing the full html of the page. Since ExtJS generates random ids, there really are not any good properties to use for finding the element.

I would recommend just using an XPath, and then use an index (if your page has multiple button elements):

 //button[1]

And adjust the index accordingly until you get the correct button to click.

Likewise, you could use the WebDriver API for driver.findElements, which will return a collection of all matching items, and then you could apply the index to that collection to get the correct button.

Nathan Dace
  • 1,545
  • 9
  • 21
0

I'm guessing that only the number at the end is generated. Try:

By.cssSelector("em.x-unselectable > button[id^='ext-gen']")

Also, looking at that <em>, are you sure that that class isn't making the button NOT clickable? By the name, it looks like it disables clicks.

ddavison
  • 28,221
  • 15
  • 85
  • 110
  • Thanks for your reply. I don't know what's the unselectablt mean. The button is clickable by manual. I tried your code. It just made me log out. The log-out button also has the similar css. :( – user3666706 May 22 '14 at 21:17
  • 1
    @sircapsalot: Almost all elements in ExtJS applications have ids starting with `ext-gen`. `x-unselectable` is the class name for anything that is "unselectable". The best way of automating ExtJS applications is to add unique class names for testing purpose, but I guess most Selenium developers won't bother doing that. – Yi Zeng May 22 '14 at 21:41
  • @Yi Zeng, actually I used class name to locate the element. But failed. Don't know why. Do you have any idea? -Jialu Li – user3666706 May 23 '14 at 12:51