Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
Is it ok if you do it in plain javascript? – MESSIAH Jul 17 at 12:21
how to? I'm really beginner, I just have Selenium IDE installed...do I need to install something else? – user2576376 Jul 17 at 12:23
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 Jul 17 at 12:24
jsfiddle.net/x6cva A very simple example – MESSIAH Jul 17 at 12:24
javascript{storedVars['options'].search("test2");} worked for me, it returned -1 or 0, it's all that I want, thanks for the support!!! – user2576376 Jul 17 at 12:34
add comment (requires an account with 50 reputation)

2 Answers

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

share|improve this answer
add comment (requires an account with 50 reputation)

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

share|improve this answer
Thanks for the suggestion, actually I used storeEval / '${variable}'.search("term") / variable_name, because I wanted it to find and store true or false if it finds or not, the verifyTextPresent command only shows green/red lines without storing a boolean value :) – user2576376 Jul 18 at 12:59
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.