Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with elements and their attributes


In the Using element attributes in XPath queries section, we saw how useful it is to find an element by looking at its attributes. An element may have the same name but a different value, so finding its according to its attributes can be extremely powerful.

Finding elements by their attributes

In this example, we will look for the button that has the value chocolate. On web page buttons, a value is what is displayed on the screen.

The syntax for looking at the attribute is node[attribute='value']. So in the case of the button with the value chocolate, it will be input[value='chocolate']. If you were to put that into Selenium IDE, it will have the format css=input[value='chocolate'] and when you click the Find button, you will see the same as shown in the following screenshot:

Another example of this is if you were trying to find an element according to its href. The syntax for this will be a[href='path']. You can try this on the Index page and try and...