I have looked up many topics over here about regex and similar stuff but still no solution.
So here my problem:
I’m testing an angular web-application with katalon right now, and there is one Element that makes me freaking out:
If I right click on a radio-button and open the so called context-menu I have 4 options, as you can see in the picture below:
Everytime I want Katalon to click on the 4. option it could not find it, cause the elements are newly generated each time. (The options 1 - 3 are working each time some how, and i don’t now why)
I saved the object several times with Object Spy.
One time the xpath looked like this:
and another time:
So the id is not everytime the same.
As I found some topics over here with a similar problem, I got the idea of using regex.
I tried to match the xpath with the following regex:
Looks good so far: https://regex101.com/r/Nzx8Kl/13
But Katalon is still not able to find the element.
Or is Katalon just still not able to handle Angular?
(as I read in other topics there have been difficulties)
Hope to get some help,
Personally, I think you are almost there. I don’t use Angular but I do use RegEx occasionally. And may I suggest to escape the opposing square bracket like you did the first, like:
Note: I also used another form of xpath since you have an id and it gets rid of one set of square brackets. Also, I’m not sure about escaping the back-slashes in the pathway.
This would never work. You can not use Regular Expression in this way. You should forget about Regexp here.
I would suggest you to try the following XPath expression:
to learn more about XPath.
Hi thank you both for your help!
The xpath I got from you kazurayam worked! Awesome!!
But just because I’m interested:
I mean the option is called “matches regex”… so this is not quite intuitive, if regular expressions actually wont (never?) work.
Up until now, I wasn’t aware that Katalon actually proposes an option “match regex” with value “//div[@id=‘mat-menu-panel-(\d)’]/div/div/a”. I was surprised to find a regex-like notation
I haven’t seen it before. It seems that
(\d) was recently added. I haven’t ever studied it. I think, this “Regex-flavored locator” syntax is something new, and not officially documented/announced at all.
I am afraid, it could be buggy. I have an opinion that this would NEVER work, though I would not bother describing it here. If you are interested, pls have a look at my discussion at another post.
At least I would not use “match regex” as I know how to write effective XPath expressions without using regex-like things. For example, see another topic TestObject that match IP Address-like string
“match regex” as Regex-powered XPath-like locator — is it officially released already? It looks experimental to me.