Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using wildcards in Selenium IDE

I'm somewhat new to automation, and am learning everything auto-didactically, so forgive me if my terminology is a bit off. I've searched hi and low for an answer to this question, and I can't seem to find anything. I presume it's my small vocabulary when it comes to this stuff... anyway...

I'm attempting to write a test that performs all the actions necessary to complete a tutorial by using the recorder. However, for one particular step, the element ID changes. For example, the ID I'm trying to click is this:

//li[@id='message_661119']/div[2]/div[2]/a/img

However, for each new user that is performing the tutorial "quest", the number of the id changes.

Is there anyway to get Selenium to recognize, or use, wildcards? Example:

//li[@id='message_******']/div[2]/div[2]/a/img

Of course, the example above does not work.

Any advice would be immensely helpful. Thank you!!

like image 316
Axos Avatar asked Oct 06 '26 22:10

Axos


2 Answers

You can use starts-with() for this:

//li[starts-with(@id, 'message_')]/div[2]/div[2]/a/img

It's one of the examples mentioned in Locating Techniques in Selenium's docs for starts-with().

like image 191
BoltClock Avatar answered Oct 09 '26 12:10

BoltClock


In Target field of the command in Selenium IDE where you can see message_123123 click on a dropdownlist and choose an option which is related to xpath:idRelative or if this one doesn't work then try another options which do not include that annoying message_123123 so this way you'll identify webpage element by it's location but not id. I solved my issue this way

like image 41
generator87 Avatar answered Oct 09 '26 12:10

generator87



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!