Robot Framework CSS Selector Help

1,278 views
Skip to first unread message

N.T.

unread,
Mar 16, 2017, 5:39:50 AM3/16/17
to robotframework-users
I want to use standard css to be able to find a certain element.

Before our search component was just id=search for all our sites (I use the same script for same sites since it's the same codebase)

Unfortunately the developer changed it so that it contains a primary key for each site/country

The search box id is now "search-component-<primary_key>

This is the sample of the html from the page

US:<input id="search-component-8798528996412">
AU:<input id="search-component-8798102914108">

Since they are all using the same code I want to be able to use the same script or locator, but robot-framework can't seem to support it.

I have tried [id|=search-component] and  [id^=search-component] . I am not sure what else I should do. I don't want to have to enter each primary key per country, because it seems too much of a hassle.
Any ideas?

 

Hélio Guilherme

unread,
Mar 16, 2017, 6:11:04 AM3/16/17
to robotframework-users
Hi,

I tested online with:
xpath=//input[starts-with(@id,'search-component-')]

And it is valid (sorry don't know how to write in CSS locator mode).

Good luck.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Mike Pietsch

unread,
Mar 16, 2017, 5:00:52 PM3/16/17
to heliox...@gmail.com, robotframework-users
Css doesn’t have a starts with…. outside of that, this site sometimes comes in handy for what you are wanting to do…


http://cssify.appspot.com

Mike



To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.

dm08

unread,
Mar 16, 2017, 5:55:54 PM3/16/17
to mikep...@level11.com, heliox...@gmail.com, robotframework-users

It has see https://www.w3schools.com/cssref/sel_attr_begin.asp

xpath=//input[starts-with(@id,'search-component-‘)] 

is equivalent of css=input[id^=’search-component’]

Dmitriy

Mike Pietsch

unread,
Mar 16, 2017, 6:46:06 PM3/16/17
to dm08, heliox...@gmail.com, robotframework-users
I did not know this.  Thanks
Reply all
Reply to author
Forward
0 new messages