selenium-ide icon indicating copy to clipboard operation
selenium-ide copied to clipboard

Add support for "patterns" for text verification

Open JamesZoft opened this issue 8 years ago • 26 comments

Raising this after seeing another user talk about it.

The old IDE allowed regex in text verification steps (and possibly other places too) eg

verify text | target | you are the * User to log in today

This should be added to the new IDE as well to keep feature parity.

JamesZoft avatar Apr 05 '18 13:04 JamesZoft

That actual syntax worked? Ha!

I always used 2 xargs with something like

command target value
verifyElementPresent //a@[starts-with(.,'you are the') and contains(.,'User to log in today')]`

98gmarquee avatar Apr 05 '18 23:04 98gmarquee

Having regex support in the IDE would be really helpful

frankkienl avatar Jun 07 '18 11:06 frankkienl

Per the old IDE spec:

Patterns are used for various reasons, e.g. to specify the expected value of an input field, or identify a select option. Selenium supports various types of pattern, including regular-expressions, all of which are described in more detail below.

String-match Patterns

Various Pattern syntaxes are available for matching string values:

glob:pattern: Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a kind of limited regular-expression syntax typically used in command-line shells. In a glob pattern, "*" represents any sequence of characters, and "?" represents any single character. Glob patterns match against the entire string.
regexp:regexp: Match a string using a regular-expression. The full power of JavaScript regular-expressions is available.
regexpi:regexpi: Match a string using a case-insensitive regular-expression.
exact:string: Match a string exactly, verbatim, without any of that fancy wildcard stuff.
If no pattern prefix is specified, Selenium assumes that it's a "glob" pattern.

For commands that return multiple values (such as verifySelectOptions), the string being matched is a comma-separated list of the return values, where both commas and backslashes in the values are backslash-escaped. When providing a pattern, the optional matching syntax (i.e. glob, regexp, etc.) is specified once, as usual, at the beginning of the pattern.

tourdedave avatar Jun 12 '18 14:06 tourdedave

Once this gets implemented, we'll need to remember to update the documentation accordingly.

tourdedave avatar Jun 12 '18 14:06 tourdedave

Hi, I have the same problem: the wildcard * is missing. Thanks by advance for the improvment, AyaSF

AyaSF avatar Jun 16 '18 10:06 AyaSF

Hi, I am using Firefox Version 60.0.2 and Selenium IDE 3.0.30. Wildcards are not working. I use command: "verify text" put in value field the following:

glob:items found and got the following error message:

Actual value '2,480 items found, displaying 1 to 20.' did not match 'glob:items found'

stuart1975 avatar Jun 21 '18 16:06 stuart1975

@cinnest There's a generic assert command. You can use it to check a variable against an expected value.

tourdedave avatar Aug 22 '18 10:08 tourdedave

I'm thinking we can add regex pretty easily, I think that glob is the issue, since JavaScript doesn't have a default glob implementation, and I don't wanna bundle that with the runner.
First off we can definitely add regex, globbing though, I see 2 solutions:

  • Bundle a globbing library with the runner
  • Convert globs to regexes in Selianize

\cc @tourdedave

corevo avatar Aug 22 '18 10:08 corevo

@tourdedave Sorry for deleting my comment. I've realized @98gmarquee had already mentioned a workaround and therefore I though my question was not relevant. It is nice tough knowing that with the assert I could indeed verify a variable. thanks

cinnest avatar Aug 22 '18 12:08 cinnest

I'm trying Selenium IDE 3 Chrome plugin for some days. It's a great and powerful tool, but I am unable to perform the most important test... How to test if a piece of text is present inside a div? asterisk character as wildcar not working in verify text, assert text, etc... There is no verify text present command. I was trying everything but I am unable to find out a solution? Why there is no substring, or * as wildcard, or a command to check a text exist somewhere on the page or inside a div? Or if there is a solution, can somebody help me how to perform it step by step? Selenium IDE 3.x

VChris1975 avatar Sep 05 '18 13:09 VChris1975

@VChris1975 I was facing a similar issue and it took me a while 'til I realize @98gmarquee had already given a solution for that: with the use of xpath and the verifyElementPresent you can check if a given element contains a string. In my case I was verifying the presence of a string in a table, so I solve the problem with the following command:

{
      "id": "90ab24b6-959a-4a98-9ef1-652bfd01c64b",
      "comment": "",
      "command": "verifyElementPresent",
      "target": "xpath=(//table[contains(.,${myString})])",
      "targets": [],
      "value": ""
    }

I guess you could use this solution too...

cinnest avatar Sep 06 '18 09:09 cinnest

@cinnest : thanks for your reply! I understand the logic, it's a very clever solution. Nice :)

VChris1975 avatar Sep 06 '18 20:09 VChris1975

Hi, I'm still new to GitHub-- does the fact that this issue is still open mean that adding wildcard support is still something that is planned to be done? None of the workarounds work for my scenario and there are many places I used a wildcard in the old version that makes it really valuable to me.

ghost avatar Dec 13 '18 21:12 ghost

I hope it's still on the cards to do. I really could have used it today... after stringing together 7 contains(.,'stuff') to verify many sentences on various pages. Stupid things had tabs and new lines in them and I couldn't get a direct text match.

98gmarquee avatar Dec 14 '18 00:12 98gmarquee

Yes, this issue is open, and we'll get to it eventually, if someone wishes to contribute we'd love the help.

corevo avatar Jan 09 '19 18:01 corevo

Thank you @98gmarquee for this. I'm in the process of taking the CP-SAT certification course, and I was stuck almost out of the gate because the training still relies on regexp being available.

jdelapp42 avatar May 01 '19 08:05 jdelapp42

Anyone has any code sample for the pattern or regex use case?

adminphdcommy avatar May 14 '19 03:05 adminphdcommy

Anyone has any code sample for the pattern or regex use case?

You can use what I posted above I think: https://github.com/SeleniumHQ/selenium-ide/issues/141#issuecomment-379110085

98gmarquee avatar May 14 '19 06:05 98gmarquee

I've updated the FAQ with the workaround using xpath (link).

tourdedave avatar Jun 23 '19 12:06 tourdedave

The example provided in the FAQ does not appear to be working. I've tried multiple things, but every use of the syntax (including the example verbatim) is returning:

Unable to locate an element with the xpath expression //a@[starts-with(.,'you are the') and contains(.,'User to log in today')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//a@[starts-with(.,'you are the') and contains(.,'User to log in today')]' is not a valid XPath expression.

Has something changed? Or am I doing something incorrectly? This is not working for me using assert element present or verify element present.

radicalbender avatar Dec 02 '19 15:12 radicalbender