How to write and regular expression in WATIR?

24 views
Skip to first unread message

rajagopalan madasami

unread,
Jun 22, 2019, 12:52:28 PM6/22/19
to Watir General
Consider the below code

b.element(name: /hello|username/).send_keys 'testid'


`
/hello|username/` represents the or operator, that means it searches the name which is hello or username, how do I write regular expression which search for hello and username?

Chuck van der Linden

unread,
Jul 19, 2019, 12:42:09 PM7/19/19
to Watir General
Well it's ruby code, so you use standard ruby regular expressions.   is what you've got above not working?   Normally I'd not use the generic 'element' but the more specific type such as .input

Can you share a sample of the HTML you are trying to interact with? 

Titus Fortner

unread,
Jul 19, 2019, 12:54:44 PM7/19/19
to Watir General
Rubular is a great resource for trying things, and there are plenty of tutorials: https://rubular.com/

If you need both, you have a lot of options, but: /hello.*username/



On Saturday, June 22, 2019 at 9:52:28 AM UTC-7, rajagopalan madasami wrote:
Reply all
Reply to author
Forward
0 new messages