Xpath issues faced while trying to automate an application


I’m facing few problems in xpath for one of the website where i have to click on an anchor tag which is inside an iframe and in a table
Using chrome got the below xpath
but the same xpath used in recording gave error. After modifying the xpath to below it ran.
(//a[contains(@id, “PB_DETAIL”)]
So why does this happen? When should we consider modifying xpath if the xpath got from firefox or chrome doesn’t work?

@sb00465063 this happens because of the dollar sign in the Xpath.

As a workaround, you can save the Xpath in a string variable and use the variable in the Xpath field in the action.


Thanks for the above solution. In the same process i’m trying to do below.
There are a number of rows in a table in which i’m trying to click on an anchor tag, navigate back and click on the anchor tag in the next row. Using the below code i was able to click on only the first row’s anchor tag and after navigating back it gave the error
"Not able to locate the element //*[@id=‘tdgbrEX_ER_APPR_VW$0’]//tbody/tr2]/td[7]"

def tBodyXpath = “//*[@id=‘tdgbrEX_ER_APPR_VW$0’]//tbody”
_ for(int j=1; j<=5; j++)_
_ {_
_ sleep(2000)_
_ driver().switchTo().frame($(byXpath("//*[@id=“ptifrmtgtframe”]")))_
_ $(byXpath("${tBodyXpath}/tr[${j}]/td[7]")).click()_
_ sleep(8000)_
_ driver().navigate().back()_
_ sleep(8000)_
_ }_

Could you do pls suggest me what i’m doing wrong here?

@sb00465063 could you please share your recording (code) and the text of the error?


Below is the code.

bot task.txt (3.2 KB)

Error is as below
12:01:24 [INFO] no such element: Unable to locate element: {“method”:“xpath”,“selector”:"//*[@id=‘tdgbrEX_ER_APPR_VW$0’]//tbody/tr[2]/td[7]/a"} (Session info: chrome=71.0.3578.98) (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: ‘’…
12:01:24 [INFO] (pace_fin_bot_task.xml:140)

Does this element exist on the page? Can you find when you use browser’s dev tools?
Can you share your recording file (.rpae)?

in the beginning used recording. For looping inside the table i made changes in xml itself. In this process
i have to click on the anchor tags in the page and scrap data and navigate and do this until finished with all the rows.

It can find the first row element, it clicks on the anchor tag and navigates back. after that it gives the error saying “no such element: Unable to locate element: {“method”:“xpath”,“selector”:”//*[@id=‘tdgbrEX_ER_APPR_VW$0’]//tbody/tr[2]/td[7]/a"}"