0

<div id=":tabs-innerCt" data-ref="innerCt" role="presentation" class="x-box-inner x-box-menu-body-horizontal" style="width: 217px; height: 30px;">
<div id=":tabs-targetEl" data-ref="targetEl" class="x-box-target" role="presentation" style="width: 181px;">
<a 
class="x-btn x-unselectable x-box-item x-toolbar-item x-btn-gw-top-menu-toolbar-small gw-top-menu-selected" hidefocus="on" unselectable="on" id="TabBar:AdminTab" tabindex="-1" componentid="TabBar:AdminTab" style="right: auto; top: 0px; margin: 0px; left: 0px;">
<span id="TabBar:AdminTab-btnWrap" data-ref="btnWrap" role="presentation" unselectable="on" style="" class="x-btn-wrap x-btn-wrap-gw-top-menu-toolbar-small x-btn-split x-btn-split-right">
<span id="TabBar:AdminTab-btnEl" data-ref="btnEl" role="presentation" unselectable="on" style="" class="x-btn-button x-btn-button-gw-top-menu-toolbar-small x-btn-text    x-btn-button-center ">
<span id="TabBar:AdminTab-btnIconEl" data-ref="btnIconEl" role="presentation" unselectable="on" class="x-btn-icon-el x-btn-icon-el-gw-top-menu-toolbar-small  " style="">
</span>
<span id="TabBar:AdminTab-btnInnerEl" data-ref="btnInnerEl" unselectable="on" class="x-btn-inner x-btn-inner-gw-top-menu-toolbar-small">Adminis<span class="g-underlined">t</span>ration</span>

</span>
</span>
</a>

I am new in Selenium. I was trying to automate a scenario in the application. I found a difficulty in executing a script. I have coded as below:

driver.findElement(By.id("TabBar:AdminTab-btnInnerEl")).click();

However this object is not identified during execution.

Could you please help me in this regard. Thanks

Enter image description here

Prakash S
  • 1
  • 1
  • Please read why a [screenshot of HTML or code or error is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. – undetected Selenium Oct 31 '18 at 11:22
  • Okay. I thought it will be easier. Here is the code. Administration – Prakash S Oct 31 '18 at 14:59
  • Instead of publishing the updates as comments edit the main question with this information for further analysis. – undetected Selenium Oct 31 '18 at 15:01
  • Do you get any exceptions? If your locator (By.id) is the wrong ou should get ElementNotFound exception. However if you don't get any exceptions but your click does not work as you expect this could be because there are several elements matching your locator or the click is performed too fast (untill the page is properly loaded) – Vladimir Efimov Oct 31 '18 at 15:12

1 Answers1

0

It could be because id you are looking for contains ':' symbol. Try

WebDriverWait wait = new WebDriverWait(driver, 10);
By locator = By.xpath("//span[contains(@id, 'AdminTab-btnInnerEl') and contains(@text, 'Adminis')]"));
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(locator);
element.click();

I found these useful:

Click a button with XPath containing partial id and title in Selenium IDE

elementToBeClickable condition

Vladimir Efimov
  • 797
  • 5
  • 13
  • Thanks for the answer. But it is not working. There are 4 different IDs for the same Tab. 2 Tabs for Admininstration and 2 tabs for the drop.down. Either I get Element not found or Element is not interactable. – Prakash S Nov 02 '18 at 13:30
  • @PrakashS updated my answer with a xPath query that will take element with id containing "AdminTab-btnInnerEl" and text containing "Adminis". Yep this is quite ugly and not very much save from ui changes but still might be useful to solve your particular case – Vladimir Efimov Nov 02 '18 at 14:40
  • I again got an error message: "no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@id, 'AdminTab-btnInnerEl') and contains(@text, 'Adminis')]"}". Looks like this is complex. – Prakash S Nov 02 '18 at 15:16
  • Hi Vladimir, it works. I have given Thread.sleep(5000); Looks like it needs some time to load the page. Thanks for your support. Thread.sleep(5000); driver.findElement(By.xpath("//*[@id='TabBar:AdminTab-btnInnerEl']")).click(); Thread.sleep(5000); – Prakash S Nov 05 '18 at 13:13
  • @PrakashS sleeps are ok for a quick resolution but they are not robust enough. I updated my answer with a preferred solution using waits. If it works for you please mark the answer as 'accepted' so others can see that is helped to solve your case – Vladimir Efimov Nov 06 '18 at 07:40