On Tue, Jan 19, 2021 at 08:23:25PM -0500,
Ofer Inbar <
c...@aaaaa.org> wrote:
> While recording a session, how can I add a step that verifies some
> text is present anywhere on the page, not at any specific path?
Found one solution, with the help of someone who knows javascript,
so I'll put it here in case it helps other people.
After completing the recording,
- Add a step after the page loads, with the "execute script" command.
- in the Target column, put this code snippet:
return document.body.textContent.indexOf('some text') >= 0
- in the Value column, put a variableName
This step will store either true or false in the named variable,
indicating whether the text was found in the page.
After the script, add a second step:
- Command: assert
- Target: variableName
- Value: true
Now, the test will fail if the text was not found.
However, we could not find any way to do this using just the Selenium
IDE commands. That does not see right to me. I hope that I missed
something, and there is a way to check without having to use a script
step, since this seems like a really simple straightforward thing that
someone might need to do.
Also, wasted a bunch of time on an earlier attempt where the script
was just return document.body.textContent - that successfully stored
the full contents of the page in the variable.
But, I could not find any way to have a subsequent step check whether
a particular string was in the variable. The assert command requires
an exact match, it doesn't look for substrings. On the web I found
some documents that suggested using a command called assertTextPresent
but the Selenium IDE does not seem to recognize that command or any
like it.
So, I still have these two questions:
1. Is there a way to check whether text is present anywhere on the
page, in a Selenium IDE step that does not rely on "execute script"?
2. Is there a way to check whether a string is in a variable as either
a substring or a regex, rather than an exact full match?
-- Cos