RAJ
RAJ

Reputation: 898

Writing RegEx to locate a certain word in a string

I have the following code

b.element(:id, "SearchFor").send_keys "843842983"
b.element(:xpath, "//input[@value='Search']").click
b.text_field(:id, "AmountPaid").set "343"
b.element(:id, "paytype0").click
b.element(:css, "label.radio-custom-label.ng-binding").click
b.element(:id, "xxx").send_keys "11"

I want to locate b.element if .send_keys has been followed

for an example,I want to locate b.element when the string is

b.element(:id, "xxx").send_keys "11"

not when

b.element(:id, "paytype0").click

I am able to locate the whole string b.element().send_keys by writing the following regular expression b.element\(.*\).send_keys but I could not locate b.element.

Can anyone help me how to do that?

Upvotes: 0

Views: 60

Answers (1)

revo
revo

Reputation: 48711

You are looking for asserting rather than matching. Asserting doesn't consume characters but matching does. For assertions you have to use lookarounds here:

b\.element(?=\([^)]*\)\.send_keys)

This is nearly your own solution but put in a positive lookahead.

Live demo

P.S. escape dots when they literally mean a dot character

Upvotes: 1

Related Questions