Thu 18 Sep 2008
In the last tutorial we learnt how to create your first basic script by recording and replaying in the IDE. We are now going to learn how to work with XPathes in your scripts
XPath is a really good way to navigate your site when there are no IDs on elements that you need to work with or is near the element you want to work with.
Note: Web browsers were never designed to handle large amounts of XPath so this means that your scripts may run slowly. You will notice this especially in Internet Explorer.
Start the tutorial by creating a script similar to the one in the last script. Only create a script for the first set of elements on this page. You will be working on the other elements later. I have made a number of programming faux pas which you need take account of in your script.
- Enter numbers into each of the text boxes and then click on one of the buttons Value 1Value 2Total=
- I have created a basic version of what a script should look like here. You will notice that instead of the click targets having a nice ID you have a very odd looking item like the following: //input[@value='divide'].
- Let's see about creating your own XPaths from whats on the pages. Selenium IDE has a very useful tool making sure that the XPath that you entered is on the screen. So we take the XPath for the divide button //input[@value='divide'] and put it in the target textbox of Selenium IDE and click on the find button.
When you click on the find button it will highlight the element as shown in the image above.
- You can specify, in a XPath any of the attributes that is in the element that you want. If you put //img[(@alt='Element Find Button')] into the IDE what element does it highlight? It will show the image that I put above.
- Now what if you had an image with no ID and a partially dynamic alt tag what would you put? My quick answer would be //img[contains(@alt,'Partial')]. This searches all the images on the page and looks for an Alt that contains "Partial". If you wanted to try the use it for this page try //img[contains(@alt,'Element')]. Selenium IDE would highlight the image above again. I am sure that you can guess by now how powerful that can become.
-
I have created the same elements again below and would like you to create another script to test the items at the top and the items at the bottom.
Value 1Value 2Total=
I have created an example here. My example will be different to yours and I will explain next why. XPath example 2
-
I have used different syntaxs in my script. Each of these is just to show you a different way of finding elements by using different kinds of syntax. There is one example where the target is defined by a number of attributes and another is defined by finding one element and then finding its sibling. Another reason for doing this is because the buttons at the top and the bottom are programmed exactly the same. It allows us to have unique identifiers for elements.
In my opinion, if an item hasn't been programmed properly, i.e., lacks an id attribute, it is best to code the Selenium test to find that item in relation to an item that *has* been programmed properly rather than to rely on meaningless indexes. This means that when reading through your script you are more likely to understand where //input[@id='BottomTotal']/following-sibling::input[contains(@value,'Add')] is compared to //li[6]/input[4]. This becomes more obvoius when you have a large number of tests in your test suite.
- We have now come to the end of this tutorial. There are a number of other items on this page that will produce a XPath for your script. Have a play and try different combinations. You can find very good examples of XPath syntax at W3C Schools. I hope that you found this tutorial very informative but if you ever find that your script is using a lot of XPath go back to the developers and remind them that it is good programming practise to put IDs on elements.
This was an excellant informative tutorial about Selenium Xpath. thanks for sharing. waiting for your updates.
ReplyDeleteSelenium Training in Chennai
Best Selenium Training Institute in Chennai
ios developer training in chennai
Best ios Training institute in Chennai
Salesforce Training Chennai
salesforce developer training in chennai
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteHadoop Training in Chennai
Cloud computing Training
Cloud computing courses in Chennai
Cloud Training in Chennai
Big Data Hadoop Training
Hadoop training institutes in chennai
Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing.
ReplyDeleteEducation
Technology
Excellent blog!!!Thanks for sharing. Keep doing more.
ReplyDeleteBest TOEFL Training Institute at T-Nagar
TOEFL Coaching Classes in Redhills
Coaching Classes for TOEFL at KK Nagar
TOEFL Coaching near me
TOEFL Class in Chennai Porur
TOEFL Training in Iyyappanthangal
TOEFL Training in DLF
Thanks for your interesting ideas.the information's in this blog is very much useful
ReplyDeletefor me to improve my knowledge.
android developer course in bangalore
Android Training courses near me
Android Training in chennai
I appreciate you sharing this article. Really thank you! Much obliged.This is one marvelous blog article.
ReplyDeleteDigital Marketing Course in Bangalore
Best Digital Marketing Classes in Bangalore
Digital Marketing Course in Chennai
Digital Marketing Training in Velachery
Digital Marketing Training in Kandanchavadi
Digital Marketing Training in Tambaram
Very good post. I have gained a lot of information from your blog, Keep sharing this kind of useful information
ReplyDeleteMicrosoft Dynamics CRM Training Courses | CRM Training in Chennai | Microsoft Dynamics Training in Chennai | Microsoft Dynamics Training in Adyar | Microsoft Dynamics Training in Tambaram | Microsoft Dynamics Training in Velachery
This comment has been removed by the author.
ReplyDeleteGreat Work. Your writing is one of a kind. The approach is very interesting to read and gives more clarity. Waiting for your future posts.
ReplyDeleteHadoop Admin Training in Chennai
Hadoop Administration Training in Chennai
Hadoop Admin Training Institute in Chennai
Hadoop Admin Training in Porur
Pega training in chennai
Pega course in chennai
Node JS Training in Chennai
Node JS Course in Chennai
Best report thanks for your post
ReplyDeleteTableau training in chennai
HI thanku so much this infromation this is greatful blog
ReplyDeletecs executive
freecseetvideolectures/
If You Are Looking For A Reliable Fx Broker, Don't Rush And Read This XM REVIEW Review First. This Is A Serious Warning Against The Broker's Illegal Activities.
ReplyDeleteYour good knowledge and kindness in playing with all the pieces were
ReplyDeletevery useful. I don’t know what I would have done if I had not
encountered such a step like this.
dba course in chennai
java training institute in chennai
node js course in chennai
Jewellery Software
ReplyDeleteJewellery Software
Jewellery Software