How to write and regular expression in WATIR?

Skip to first unread message

rajagopalan madasami

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

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

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:

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
0 new messages