Moving elements on the page
As I just mentioned, Selenium, when using the value of the ID attribute, can find elements on a page even if they are moved. Click on the button with the text Random on the Chapter 2 page of the site (you can do this manually), and then run the script that we created earlier. You will see that your test executes successfully.
Finding elements by name
Elements do not necessarily have ID attributes on all of them. Elements can have names that we can use to locate them. In the Target textbox, this would look like name=Element
. Try the following example to see how it works:
Open Selenium IDE.
Navigate to http://book.theautomatedtester.co.uk/chapter2 and click on the Firebug icon.
Find any element that you want to interact with and, in the Target textbox of Selenium IDE, place the value of its name attribute. For example, use
but2
, as in the following screenshot, against http://book.theautomatedtester.co.uk/chapter2:Type the
click
command into the Command select box.Play...