Selenium IDE: Verify text is present anywhere on the page? IDE?

855 views
Skip to first unread message

Ofer Inbar

unread,
Jan 19, 2021, 8:24:25 PM1/19/21
to seleniu...@googlegroups.com
Another thing that I thought should be straightforwardly easy to do in
the Selenium IDE recorder, but I'm having a hard time finding an answer:

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?

I tried adding a "verify text" step, then manually clearing the Target
column, but that gives me an error that it's not allowed to be empty.

Web searches found me some references to a verifyTextPresent command
that apparently used to exist and would do exactly this, but I could
not find that in the IDE. So I saved a .side file, edited the .side
file to change the "command": "verifyText", to say verifyTextPresent,
and re-loaded the .side file into the IDE. But then it gave an error
on that command, so I guess it's no longer supported.

So how do I do this? I don't care where that text is on the page,
I just want to ensure that string is present somewhere.
-- Cos

venkatesh iyengar

unread,
Jan 19, 2021, 8:35:48 PM1/19/21
to seleniu...@googlegroups.com
Happy Mornings Ofer, 

Let me give a try at my end to let you know as I use more of Web driver coding than selenium ide.

Regards, 
Venkatesh 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/20210120012325.GT14773%40miplet.aaaaa.org.

Bala Murugan V

unread,
Jan 19, 2021, 11:54:34 PM1/19/21
to seleniu...@googlegroups.com
Hi,
Please use the below comment which store all html source code of that page. From here use java script find out the expected text is present or not (ex:includes())
storeHtmlSource ( variableName )
Thanks,
Bala

Ofer Inbar

unread,
Jan 20, 2021, 12:43:26 AM1/20/21
to seleniu...@googlegroups.com
Bala Murugan V <balu...@gmail.com> wrote:
> Please use the below comment which store all html source code of that page.
> >From here use java script find out the expected text is present or not
> (ex:includes())
> storeHtmlSource ( variableName )

I can't figure out what you're suggesting I do.
I'm making a recording in Selenium IDE, and I can also edit steps
using the IDE. Or, I can save to a .side file, and edit that .side
file. I don't see what you're saying I should do.

(Although I know a few programming languages, I do not know javascript)
-- Cos

Ofer Inbar

unread,
Jan 21, 2021, 1:57:50 PM1/21/21
to seleniu...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages