How to handle dynamic webpages with changing XPaths?

Hi Team,

Greetings!

As I observe, the web system I am working on has parts of its pages, may it be anchors/links, buttons, etc. dynamically changes in terms of XPath … for example:

/html/body/div[6]/div/div[2]/div/div/div[3]/div/button[2]/span
/html/body/div[7]/div/div[2]/div/div/div[3]/div/button[2]/span
/html/body/div[8]/div/div[2]/div/div/div[3]/div/button[2]/span
/html/body/div[9]/div/div[2]/div/div/div[3]/div/button[2]/span
/html/body/div[10]/div/div[2]/div/div/div[3]/div/button[2]/span

… causing failure to be detected by OpenRPA, unless all those XPaths are defined in the codes, and have to be checked each one if element is present or not.

Your assistance will be so appreciated.

Massive thanks

Hi

Don’t use full Xpath for this one. You need to check what attributes or even text headers that are unique to the element you want to select.

You may follow this blog: https://blog.apify.com/xpath-contains/

Super thanks … I was able to use: //span[contains(text(), ‘Apply’)]

… however, failed when I use to search for elements based on any attributes as id, class, etc. … not sure why …

what xpath was failing ? and was it failing with an error or just not finding anything ?
it’s important the xpath returns the ELEMENT, if you “select” a property, then that will fail in OpenRPA, since the OpenRPA chrome extension only supports parsing elements.

Valid

//div[contains(@class, 'active')]

Not valid (valid XPath, but the extension does not understand it)

//div[contains(@class, 'active')/@lang]

or

//div[contains(@class, 'active')/text()]

Hi All,

I just realized, those xpaths I create, say, //div[contains(@class, ‘bds-avatar–initials’)] returns many elements instead of a single one, causing the issue. But when I make sure only a single element returns out of the xpath I create, then I successfully have OpenRPA identify the element.

Cheers :wink:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.