0
votes

I'd like to know how to verify if there's a word inside a string (using variables).

For example, I have a variable called options that has a string "test,test2,test3" (without quotes) inside it. I want to verify if this string contains the word test2.

I've tried this way:

  1. command: store // target: test,test2,test3 // value: options
  2. command: storeEval // target: javascript{storedVars['options'].contains("test2");} // value: result

I want Selenium to store TRUE or FALSE on that variable result if it finds or not the word test2 on this string, but I'm getting this error:

[error] Unexpected Exception: TypeError: storedVars.options.contains is not a function. fileName -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 2545

Any ideas?

Screenshoot: http://oi40.tinypic.com/2qibcxf.jpg

2
Is it ok if you do it in plain javascript? - HIRA THAKUR
how to? I'm really beginner, I just have Selenium IDE installed...do I need to install something else? - sanjuro8998
I can't quite remember as its been a while since I used the IDE but I'm fairly sure you'll need to loop over the contents of your options array to find your boolean result. - Mark Rowlands
jsfiddle.net/x6cva A very simple example - HIRA THAKUR
javascript{storedVars['options'].search("test2");} worked for me, it returned -1 or 0, it's all that I want, thanks for the support!!! - sanjuro8998

2 Answers

1
votes

javascript{storedVars['options'].search("test2");} worked.

0
votes

If you're using the IDE, you can simply use the command below:

verifyTextPresent | storedVars['options'] | test2

This line will pass (turn green) if the text is found, and will fail (red) if it isn't.

Klendathu