0

I have a button on a website built with sencha/extjs. Currently the button id is savebutton-1550-btnEl, but this changes everytime the page is loaded. I know that the button is disabled, but for testing purposes, I'd like to set this button as enabled, and then click it.

How would I go about finding this element each time, and then disabling it and clicking it with Java Selenium?

I'm guessing I'll have to execute some javascript, but I'm having a hard time finding the target for the javascript.

Sakamoto Kazuma
  • 2,573
  • 7
  • 34
  • 75

3 Answers3

0

To locate the element you will have to use part of the DOM surrounding the element as a unique locator. It is impossible to give a more specific answer without seeing the DOM you are working on, but you may try something like:

WebElement saveButton = driver.findElement(By.xpath("//button[text()='Save']");

For changing the element to enabled, take a look at this answer: Selenium Webdriver - click on hidden elements

Community
  • 1
  • 1
Lev
  • 100
  • 8
0

Also a longer term solution might be to work with development to see if they can build in a unique locator especially since this probably wont be the only object that you have problems with. At my company we use the "class" field to uniquely identify objects in extjs.

jason12459
  • 19
  • 2
0

I override the the class "AbstractComponent":

Ext.define('Foo.overrides.AbstractComponent', {
    override: 'Ext.AbstractComponent',

    onBoxReady: function () {
      var me = this;
      var el = me.getEl();

      if (el && el.dom && me.itemId) {
        el.dom.setAttribute('data-test', me.itemId);
      }
      me.callOverridden(arguments);
    }
  });

If you set in configuation of the button the "itemId", you can be accessed the button via seleniumas follows:

IWebElement element = webDriver.FindElement(By.XPath($"//*[@data-test='{itemId}']"));
Larissa
  • 23
  • 4