But sometime we face the problems of idenfying the objects on a page which have same attributes. When we get more than
one element which are same in attribute and name like multiple checkboxes with same name and same id. More than one button having
same name and ids. There are no way to distingues those element. In this case we have problem to instruct selenium to identify a perticular
object on a web page.
I am giving you a simple example . In the below html source there are 6 checkboxes are there having same type and same name.
It is really tough to select third or fifth.
<html>
<body>
<input type='checkbox' name='chk'>first
<br><input type='checkbox' name='chk'>second
<br><input type='checkbox' name='chk'>third
<br><input type='checkbox' name='chk'>forth
<br><input type='checkbox' name='chk'>fifth
<br><input type='checkbox' name='chk'>sixth
</body>
</html>
Thare are some function we can use in Xpath to identify the abject in above cases.
An XPath expression can return one of four basic XPath data types:
* String
* Number
* Boolean
* Node-set
XPath Type : Functions
Node set : last(), position(), count(), id(), local-name(), namespace-uri(), name()
String : string(), concat(), starts-with(), contains(), substring-before(), substring-after(), substring(), string-length(), normalize-space(), translate()
Boolean : boolean(), not(), true(), false(), lang()
Number : number(), sum(), floor(), ceiling(), round()
I will show you how we can use some of these above functions in xpath to identify the objects.
Node Set : last()
In the above html file there are six checkboxes and all are having same attributes (same type and name)
How we can select the last checkbox based on the position. We can use last() function to indentify the last object among all similar objects.
Below code will check or uncheck the last checkbox.
selenium.click("xpath=(//input[@type='checkbox'])[last()]");
How we can select the second last checkbox and third last checkbox. We can use last()- function to indentify the last object among all similar objects.Below code will check or uncheck the second last checkbox and thrid last checkbox respectively.
selenium.click("xpath=(//input[@type='submit'])[last()-1]");
selenium.click("xpath=(//input[@type='submit'])[last()-2]");
Node Set : position()
If you want to select any object based on their position using xpath then you can use position() function in xpath.
You want to select second checkbox and forth checkbox then use below command
selenium.click("xpath=(//input[@type='checkbox'])[position()=2]");
selenium.click("xpath=(//input[@type='checkbox'])[position()=4]");
above code will select second and forth checkbox respectively.String : starts-with()
Many web sites create dynamic element on their web pages where Ids of the elements gets generated dynamically.
Each time id gets generated differently. So to handle this situation we use some JavaScript functions.
XPath: //button[starts-with(@id, 'continue-')]
Sometimes an element gets identfied by a value that could be surrounded by other text, then contains function can be used.
To demonstrate, the element can be located based on the ‘suggest’ class without having
to couple it with the ‘top’ and ‘business’ classes using the following
XPath: //input[contains(@class, 'suggest')].
Example: How to click on link on the page which has many links with same name and attributes.
Below is the example of your html which has 3 links with same name and same attributes
<html>
<body>
<a href="http://www.google.com" name="a1">Link</a>
<a href="http://www.yahoo.com" name="a1">Link</a>
<a href="http://www.gmail.com" name="a1">Link</a>
</body>
</html>
If you want to click on first link then use below command
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[@name='a1'])[position()=1]</td>
<td></td>
</tr>
If you want to click on second link then use below command
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[@name='a1'])[position()=2]</td>
<td></td>
</tr>
If you want to click on last link or third link then use below command
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[@name='a1'])[last()]</td>
<td></td>
</tr>
OR
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[@name='a1'])[position()=3]</td>
<td></td>
</tr>
Selenium RC.
Click on first link
selenium.click("xpath=(//a[@name='a1'])[position()=1]");
selenium.waitForPageToLoad("80000");
Click on second link
selenium.click("xpath=(//a[@name='a1'])[position()=2]");
selenium.waitForPageToLoad("80000");
Click on last link
selenium.click("xpath=(//a[@name='a1'])[last()]");
selenium.waitForPageToLoad("80000");
Click on thrid link
selenium.click("xpath=(//a[@name='a1'])[position()=3]");
selenium.waitForPageToLoad("80000");
For rest of the function please keep reading my blogs i will be posting very soon.
Thank you so much for the easy to read and detailed explantion!
ReplyDeleteThanks a ton !!! this really helped me a lot ....:)
ReplyDeletei need details knowledge of xpaths, where will i get it from ? please suggest
really super brother.
ReplyDeleteThank you! This helped solving my problem!
ReplyDeleteThanks a lot, nice tips but how can we use above Xpath expression in selenium Ide target field because I tried unfortunately didnt worked for me...could you please help me in that?
ReplyDeleteClick on first link
ReplyDeleteselenium.click("xpath=(//a[@name='a1'])[position()=1]");
selenium.waitForPageToLoad("80000");
Click on second link
selenium.click("xpath=(//a[@name='a1'])[position()=2]");
selenium.waitForPageToLoad("80000");
Click on last link
selenium.click("xpath=(//a[@name='a1'])[last()]");
selenium.waitForPageToLoad("80000");
Click on thrid link
selenium.click("xpath=(//a[@name='a1'])[position()=3]");
selenium.waitForPageToLoad("80000");
i try to use the above code with for loop :
for (int i = 0; i < rowCount_tpsumry; i++)
{
selenium.click("xpath=(//a[@name='a1'])[position()=i]");
}
but it is not working.
please suggest me to use it with for loop.
Thanks in advance.
After clicking on Link go back to the home page for each iteration.
DeleteUse driver.navigate().to() for backward functionality.
Code will work
for (int i = 0; i < rowCount_tpsumry; i++)
ReplyDelete{
selenium.click("xpath=(//a[@name='a1'])[position()=i]");
selenium.waitForPageToLoad("80000");
}
nice.. one... very useful.. easy to understand..
ReplyDeletenice.. one... very useful.. easy to understand..
ReplyDeleteGood one man. your explanation is easy to understand.
ReplyDeleteGreat post! We are linking to this great post on our website.
ReplyDeleteKeep up the great writing.
Here is my web blog: elektronisk cigaret
Thanks , I've recently been searching for info about this subject for a while and yours is the best I've came
ReplyDeleteupon so far. But, what about the bottom line? Are
you sure in regards to the source?
my web blog :: elektronisk cigaret
We stumbled over here coming from a different page and thought I may
ReplyDeleteas well check things out. I like what I see so i am just following you.
Look forward to finding out about your web page
for a second time.
my website ... e-cigaretter
You\'ll also business save them from having to pay First Quantum more than $1bn in compensation. I believe that the head is the" level playing field, with ministers who are looking for change. As business a communications professional, one of the biggest losers of today's sell-οff
ReplyDeleteafter the Bank of Japan govеrnоr, vοwed to achieѵe the deѕiгed bеnefits.
mу wеb pаge ... tv.wheatworkspro.com
I needed to thank you for this fantastic read!! I absolutely enjoyed every little
ReplyDeletebit of it. I've got you book-marked to check out new stuff you post…
Also visit my weblog: e-cigs
Hello there! This post couldn't be written much better! Reading through this article reminds me of my previous roommate! He constantly kept preaching about this. I will send this information to him. Pretty sure he will have a great read. Thanks for sharing!
ReplyDeleteReview my weblog ryge væsker
I absolutely love your blog and find almost all of your post's to be exactly I'm looking for.
ReplyDeleteDoes one offer guest writers to write content available for you?
I wouldn't mind creating a post or elaborating on a lot of the subjects you write in relation to here. Again, awesome weblog!
Here is my blog: e-cigarette refill
I have read so many content on the topic of the blogger lovers except this article is actually
ReplyDeletea pleasant article, keep it up.
Feel free to visit my blog ryge væsker
Pretty! This has been an incredibly wonderful post.
ReplyDeleteMany thanks for supplying these details.
Feel free to surf to my web blog: zemos98.org
Does your website have a contact page? I'm having problems locating it but, I'd like to shoot you an email.
ReplyDeleteI've got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it grow over time.
my weblog :: quit smoking fags
Hello, i think that i saw you visited my weblog so i came to “return the
ReplyDeletefavor”.I am trying to find things to enhance my website!
I suppose its ok to use some of your ideas!!
Feel free to surf to my website ... billig ecigaret
Simply want to say your article is as astounding.
ReplyDeleteThe clarity in your post is simply spectacular and i could assume you are an expert on this subject.
Well with your permission allow me to grab your RSS feed to keep up to date
with forthcoming post. Thanks a million and
please carry on the enjoyable work.
Also visit my web-site ... tobacco e-liquid
Does your website have a contact page? I'm having problems locating it but, I'd like
ReplyDeleteto shoot you an email. I've got some suggestions for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.
Also visit my website; awesomeindiefilms.doobious.org
I'm truly enjoying the design and layout of your website. It's a
ReplyDeletevery easy on the eyes which makes it much more pleasant for me
to come here and visit more often. Did you hire out a designer
to create your theme? Excellent work!
Also visit my webpage ... http://timemoney.com.ua/node/7268/
If some one wants expert view regarding blogging then i advise him/her to go to see this web site,
ReplyDeleteKeep up the nice job.
my web blog; billig e-væske
Good article and keep posting ,
ReplyDeleteselenium training
Great article with neatly explained. its pleasure to learn selenium from your article for beginners. thanks for sharing Best selenium training institute in chennai
ReplyDeleteFrom My search…Creating Experts provides Best SAP MM training with real time projects assistance. Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage. They also provide placement assistance in leading MNC companies across the globe according to the current requirements.
ReplyDeleteAnd these are the Best SAP MM training institute which provides Real Time Hands on Training…
Codedion Technologies-9003085882
Creating Experts-8122241286
They also providing both Classroom/Online Training
Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
ReplyDeleteSelenium Training Institute in Chennai
FREE SELENIUM TUTORIALS
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteSelenium Training in Bangalore
Thanks a lot very much for the high quality and results-oriented help.
ReplyDeleteI won’t think twice to endorse your blog post to anybody who wants
and needs support about this area.
java training in chennai
java training in bangalore
Webtrackker is one only IT company who will provide you best class training with real time working on marketing from last 4 to 8 Years Experience Employee. We make you like a strong technically sound employee with our best class training.
ReplyDeleteWEBTRACKKER TECHNOLOGY (P) LTD.
C - 67, sector- 63, Noida, India.
F -1 Sector 3 (Near Sector 16 metro station) Noida, India.
+91 - 8802820025
0120-433-0760
Best SAS Training Institute in delhi
SAS Training in Delhi
SAS Training center in Delhi
Best Sap Training Institute in delhi
Best Sap Training center in delhi
Sap Training in delhi
Best Software Testing Training Institute in delhi
Software Testing Training in delhi
Software Testing Training center in delhi
Best Salesforce Training Institute in delhi
Salesforce Training in delhi
Salesforce Training center in delhi
Best Python Training Institute in delhi
Python Training in delhi
Best Python Training center in delhi
Best Android Training Institute In delhi
Android Training In delhi
best Android Training center In delhi
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
Thank you for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit.
ReplyDeletesap abap training online
3D Animation Training in Noida
ReplyDeleteBest institute for 3d Animation and Multimedia
Best institute for 3d Animation Course training Classes in Noida- webtrackker Is providing the 3d Animation and Multimedia training in noida with 100% placement supports. for more call - 8802820025.
3D Animation Training in Noida
Company Address:
Webtrackker Technology
C- 67, Sector- 63, Noida
Phone: 01204330760, 8802820025
Email: info@webtrackker.com
Website: http://webtrackker.com/Best-institute-3dAnimation-Multimedia-Course-training-Classes-in-Noida.php
Graphics designing training institute in Noida
ReplyDeleteBest Graphics training institute in Noida, Graphic Designing Course, classes in Noida- webtrackker is providing the graphics training in Noida with 100% placement supports. If you are looking for the Best Graphics designing training institute in Noida For more call - 8802820025.
Graphics designing training institute in Noida, Graphics designing training in Noida, Graphics designing course in Noida, Graphics designing training center in Noida
Company address:
Webtrackker Technology
C- 67, Sector- 63, Noida
Phone: 01204330760, 8802820025
Email: info@webtrackker.com
Website: http://webtrackker.com/Best-institute-for-Graphic-Designing-training-course-in-noida.php
Latest News in Hindi
ReplyDeleteLatest News in Hindi- Hindustan channel is the best online web portal in india where you read the all latest indian news in hindi. if you are looking the Latest News in Hindi, live news channel, hindi news channel, live news channels in hindi, live hindi channels then hindustan channel is best for you.
Latest News in Hindi
Company address:
C- 67, Sector- 63, Noida
Phone: 01204330760, 8802820025
URL: https://hindustanchannel.com
Sap fico training institute in Noida
ReplyDeleteSap fico training institute in Noida - Webtrackker Technology is IT Company which is providing the web designing, development, mobile application, and sap installation, digital marketing service in Noida, India and out of India. Webtrackker is also providing the sap fico training in Noida with working trainers.
WEBTRACKKER TECHNOLOGY (P) LTD.
C - 67, sector- 63, Noida, India.
F -1 Sector 3 (Near Sector 16 metro station) Noida, India.
+91 - 8802820025
0120-433-0760
0120-4204716
EMAIL: info@webtrackker.com
Website: www.webtrackker.com
Sap fico training institute in Noida
ReplyDeleteSap fico training institute in Noida - Webtrackker Technology is IT Company which is providing the web designing, development, mobile application, and sap installation, digital marketing service in Noida, India and out of India. Webtrackker is also providing the sap fico training in Noida with working trainers.
WEBTRACKKER TECHNOLOGY (P) LTD.
C - 67, sector- 63, Noida, India.
F -1 Sector 3 (Near Sector 16 metro station) Noida, India.
+91 - 8802820025
0120-433-0760
0120-4204716
EMAIL: info@webtrackker.com
Website: www.webtrackker.com
Sap fico training institute in Noida
ReplyDeleteSap fico training institute in Noida - Webtrackker Technology is IT Company which is providing the web designing, development, mobile application, and sap installation, digital marketing service in Noida, India and out of India. Webtrackker is also providing the sap fico training in Noida with working trainers.
WEBTRACKKER TECHNOLOGY (P) LTD.
C - 67, sector- 63, Noida, India.
F -1 Sector 3 (Near Sector 16 metro station) Noida, India.
+91 - 8802820025
0120-433-0760
0120-4204716
EMAIL: info@webtrackker.com
Website: www.webtrackker.com
It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
ReplyDeletepython training in chennai
Python Online training in usa
python course institute in chennai
How to test a targeted checkbox only for say 4th checkbox always ,and the checkbox count may alter and position also changes.how to handle
ReplyDeleteHadoop training center in faridabad
ReplyDeleteHadoop training center in ghaziabad
Hadoop training center in greater noida
Hadoop training center in karnal
python Training center in noida
ReplyDelete
ReplyDeletedigital marketing course in noida
digital marketing institute in noida
SFDC Training path is supposed to assure which you study and enforce the thoughts of SFDC platform developer and bypass any required accreditation checks on your first attempt. Quality in elegance guidance will assist you spot how to make bigger salesforce highlights utilizing the state-of-the-art and automated abilities of SFDC code and visual pressure. The down to earth fingers-on mastering approach observed within the route will assure you land role prepared earlier than the cease of it. For best Salesforce Training in Noida aspirants needs to get training from authorised centre for ultimate solutions. Salesforce training in noida sector 63
ReplyDeleteAndroid training center in noida sector 15 Android is an open source and Linux-based Operating System Android is an open source and Linux-based Operating System for PDAs, for instance, mobile phones and tablet PCs. Android was made by the Open Handset Alliance, drove by Google, and distinctive associations. Android training in noida Webtrackker Technology offers a united approach to manage application headway for mobile phones which suggest engineers require create for Android, and their applications should have the ability to continue running on different contraptions controlled by Android.
ReplyDeleteAndroid training center in noida sector 3 The Android Open Source Project made a Compatibility Test Suite, or cts, that you can use to test an app's compatibility with the Apps working framework. Accessible free on the Web, the Webtrackker Technology best Android training institute and creates a report on each application's appropriateness for arrangement. What's more, Google arrangements to offer a Web-based service that will allow application developers to publish their CTS reports to a public database. And the last guarantees that a particular software application meets the standards required for sending on cell phones that run the Android working system.
ReplyDeleteAndroid, MAC & Phone gap is the most popular operating system using in tablet iPhone & smarts phone. Because of the rising the request and high offering of Apps based mobile devices, demanding of smart phone in the market is being going up step by step. The most reason of requesting this is Android is user friendly environment means that simple to use as contrast with other working frameworks in savvy phone.
ReplyDeleteAndroid, MAC & Phone gap is the most popular operating system using in tablet iPhone & smarts phone. Because of the rising the request and high offering of Apps based mobile devices, demanding of smart phone in the market is being going up step by step. The most reason of requesting this is Android is user friendly environment means that simple to use as contrast with other working frameworks in savvy phone.
ReplyDeleteThe applications programming designers need to much consider a long series of screen sizes, hardware specifications and configurations due to strong competition in the mobile software and changes within each of the platforms. The development of mobile applications is always developing, both as far as wage and jobs created.
Initially, Andy Rubin set up Android Incorporation in Palo Alto, California, United States in October, 2003. In seventeenth August 2005, Google secured android Incorporation. Beginning now and into the not too far-removed, it is in the support of Google Incorporation. The key administrators of Android Incorporation are Andy Rubin, Rich Miner, Chris White and Nick Sears. Originally proposed for camera yet moved to cutting edge PDAs later in this way of low market for camera in a way. Android is the moniker of Andy Rubin given by partners by respectability of his affection to robots. In 2007, Google reports the progress of OS. In 2008, HTC moved the key android adaptable.
ReplyDeleteI am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Great efforts.
ReplyDeleteLooking for Big Data Hadoop Training Institute in Bangalore, India. Prwatech is the best one to offers computer training courses including IT software course in Bangalore, India.
Also it provides placement assistance service in Bangalore for IT. Best Data Science Certification Course in Bangalore.
Some training courses we offered are:
Big Data Training In Bangalore
big data training institute in btm
hadoop training in btm layout
Best Python Training in BTM Layout
Data science training in btm
Effective blog with a lot of information. I just Shared you the link below for ACTE .They really provide good level of training and Placement,I just Had Automation Testing Classes in ACTE , Just Check This Link You can get it more information about the Automation Testing course.
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
Hey guy's i have got something to share from my research work
ReplyDeleteTukui
Skewed
Mpi-Sws
Visit Bharat Go Digital Academy to learn the digital marketing skills in India.
ReplyDeleteGood blog,
ReplyDeleteDigital Marketing, Digital Marketing Online Training, Digital Marketing Training Programs, Women Entrepreneurship, Women Entrepreneurship Training Programs, Digital marketing online video course, Women Entrepreneurship Online Certification Course, Business coaching, Training for Business owners, Business coaching for women, young entrepreneurs training
https://www.eminentdigitalacademy.com
1 Year Free Support and Access
ReplyDelete+ 100% Practical Job Oriented Training.
+ 12 Types of Certifications to boost your resume
+ 2 Month Internship program on Live Projects.
+ Trending & most important skill required these days.
ReplyDeleteThat is nice article from you , this is informative stuff . Hope more articles from you . I also want to share some information about Pet Dermatology in Vizag
golden goose outlet
ReplyDeleteoff white outlet
jordans
kyrie shoes
off white
golden goose black friday
supreme hoodie
fear of god hoodie
goyard
goyard outlet