What is the best way to verify/assert an attribute is absent/not present

3,603 views
Skip to first unread message

ejmowrer

unread,
Sep 15, 2010, 8:03:48 PM9/15/10
to Selenium Users
I'm currently limited to just Selenium Core and the IDE.
verifyAttribute won't work for me because I need to check if the
attribute is absent and verifyNotAttribute is strictly concerned with
the value of the attribute and not its existence (in other words it
will error out if the attribute is not there).

I've seen references to setting up error handling to catch this in
various languages, but I don't think I have that option with straight
Selenium Core (unless I want to make my own extension or fiddle around
with executing some sort of a javascript function that does this
assertion for me). Are there any other options that will work for me
straight out of the box?

ejm

Bob Zakes

unread,
Sep 20, 2010, 2:12:21 PM9/20/10
to Selenium Users
Have you tried verifyElementNotPresent ?

Bindu Laxminarayan

unread,
Sep 20, 2010, 4:02:24 PM9/20/10
to Selenium Users
Bob is correct. You can use verifyElementNotPresent, but identify the
locator with the attribute you want to test.

For Example:

Navigate to http://www.hexbytes.com

Here you will find an element: <a href="http://
www.hexbytes.com">Hexbytes</a>

Now if you want to verify the existence of an attribute id for the
above element, you can use verifyElementNotPresent-Function and //
a[@id] as a locator. Run the test.

Selenium IDE script for this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>verifyElementNotPresent</td>
<td>//a[@id]</td>
<td></td>
</tr>

</tbody></table>
</body>
</html>


Thanks
Bindu Laxminarayan

ejmowrer

unread,
Sep 21, 2010, 12:13:09 PM9/21/10
to Selenium Users
Thanks Bindu,

That sounds like it should work for me. I'll give it a try. Thanks!

ejm

On Sep 20, 1:02 pm, Bindu Laxminarayan <bindu.laxminara...@gmail.com>
wrote:
> Bob is correct. You can use verifyElementNotPresent, but identify the
> locator with the attribute you want to test.
>
> For Example:
>
> Navigate tohttp://www.hexbytes.com
>
> Here you will find an element: <a href="http://www.hexbytes.com">Hexbytes</a>
> > > ejm- Hide quoted text -
>
> - Show quoted text -

redevill

unread,
Sep 23, 2010, 9:46:56 AM9/23/10
to Selenium Users
Perhaps you can help me.
I am trying to something similar. Only I want to check that part of
the attribute exists.

In your example I'd like to do something like:
substring(a[@id='MyAttr'],1,5)

The substring gives me an error.
Is there an alternative?

Thanks


On Sep 20, 4:02 pm, Bindu Laxminarayan <bindu.laxminara...@gmail.com>
wrote:
> Bob is correct. You can use verifyElementNotPresent, but identify the
> locator with the attribute you want to test.
>
> For Example:
>
> Navigate tohttp://www.hexbytes.com
>
> Here you will find an element: <a href="http://www.hexbytes.com">Hexbytes</a>

Jayakumar C

unread,
Sep 24, 2010, 3:01:57 AM9/24/10
to seleniu...@googlegroups.com
Try,
verifyAttribute | locator@attribute | glob:*some text*

You can also use 'regexp' in place of 'glob'

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--
Jayakumar
Reply all
Reply to author
Forward
0 new messages