Add support for "patterns" for text verification
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.
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')]` |
Having regex support in the IDE would be really helpful
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.
Once this gets implemented, we'll need to remember to update the documentation accordingly.
Hi, I have the same problem: the wildcard * is missing. Thanks by advance for the improvment, 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'
@cinnest There's a generic assert command. You can use it to check a variable against an expected value.
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
@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
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 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 : thanks for your reply! I understand the logic, it's a very clever solution. Nice :)
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.
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.
Yes, this issue is open, and we'll get to it eventually, if someone wishes to contribute we'd love the help.
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.
Anyone has any code sample for the pattern or regex use case?
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
I've updated the FAQ with the workaround using xpath (link).
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.