dzharii / swd-recorder

Selenium WebDriver Page Recorder (Page Objects)
MIT License
189 stars 71 forks source link

cannot get absolute xpath like firepath or firebug #46

Closed dannydong closed 8 years ago

dannydong commented 8 years ago

Dear authors,

This is a great application for web automation, but I am experiencing a problem during my work with it. The swd-recorder captures the xpath which is something like (in the output pox file):

id("svep_19_i0_508")/div[1]/img[1]

However, the id of "svep_19_i0_508" always changes because of the id is generated dynamically by the Web server, so when I re-open the page, I always fail to find the page element recorded.

What I expect is something similar with :"html/body/section/section/x1-workspaces/div/div[2]/x1-tabset/ul/li[7]/a

A work-round is to use the firepath to get the absolute xpath, so I hope the swd-recorder can extract the absolute xpath of page elements, probably it can re-use the interface of firepath or firebug?

Very appreciate with your help.

sergueik commented 8 years ago

Hello

It is clearly possible to generate a locator in a format

return '//' + elementTagName + '[@id="' + element.id + '"]';

rather than

return 'id("' + element.id + '")';

(with possible variations like the one you provided) - the result is simply a string. Isn't the usage of absolute XPaths discouraged in general ?

dzharii commented 8 years ago

Hi @dannydong,

I have created a patch that might provide a hotfix for this case.

  1. Close Page Recorder
  2. Open folder SwdPageRecorder_v2...\JavaScript\
  3. Rename file ElementSearch.js to Backup_ElementSearch.js
  4. Download, unzip and copy patched ElementSearch.js to the folder SwdPageRecorder_v2...\JavaScript\

PATCH ATTACHMENT ElementSearch.zip

dannydong commented 8 years ago

Thank a lot @dzharii and @sergueik, I have done a quick test with the patch, it does work! Very helpful, appreciate with your help. Great!

dannydong commented 8 years ago

I will close the issue since it was resolved

dzharii commented 8 years ago

@dannydong I am glad it has helped you!