I have a button element in a webpage
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" role="button" title="Close">
<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">Close</span>
</button>
I am trying to locate it using this Xpath: "//button[@class = 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close']"
This button element appears only when I choose to view an item within the page. There are multiple items within the page; so I need to open one by one after closing the one already open.
I need to use the Xpath multiple times to do my operation
btnWorkItemClose = bla.elementByXpath("//button[@class = 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close']");
btnWorkItemClose.click();
backlogGrid.sendKeys(Keys.ARROW_DOWN);
backlogGrid.sendKeys(Keys.ENTER);
doSomeFuntionWithTheWorkItem();
btnWorkItemClose = bla.elementByXpath("//button[@class = 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close']");
btnWorkItemClose.click();
The element is successfully located during the first instance but not in the second usage. I got the exception
"no such element: Unable to locate element: {"method":"xpath","selector":"//button[@class = 'ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close']"}" ]
Note: When I used the Xpath in the webpage manually, it found the element accurately & I have tried different wait methods but didn't help either.
However, when I used Xpath "//button[@title= 'Close']"
, it worked alright both the instances.
Can you please advise what is happening here?