ruby - How do I group and repeat a string of commands with a changed variable in each repetition -
i want repeat same process in watir (word) different variable without writing out whole code again in .rb file. without having write this:
website = somewebsite.com word = someword browser.goto(website) if browser.text.include?(word) puts(website) end word = someotherword browser.goto(website) if browser.text.include?(word) puts(website) end word = anotherword browser.goto(website) if browser.text.include?(word) puts(website) end
how can this?
thanks.
the website same? leave outside loop.
browser.goto(website) content = browser.text %w(some_word some_other_word another_word).each |word| puts(website) if content.include?(word) end
if want better performance, omit loop altogether:
words = %w(some_word some_other_word another_word) browser.goto(website) puts website if browser.text.match(regexp.union(words))
Comments
Post a Comment