what is the need of xpath when you have attributes like id ,class,name in selenium?

0 votes
Jun 1, 2018 in Selenium by walter 123
• 240 points
130 views

1 answer to this question.

0 votes

It is not necessary that every element can be identified uniquely by using just using id, class OR name .

In that scenario xpath comes into play. For example:

The website of Edureka has courses tab. If you want to identify the courses tab, you will see there is no id, name or class to identify it. In such scenarios you need to use the Xpath so that you can identify the web element uniquely and work on it.

Here, you have the id for navigation bar but you need to identify a different element i.e “course”. So, you can use the “id of navbar” for further locating your course element via Xpath.

Xpath for the Webelement course is :

 .//*[@id='navbar']/ul/li[2]/a

If you go to your google chrome ,Right click, go to inspect and press CTRL+F and paste this Xpath ,You will see that your element has been identified uniquely.

answered Jun 1, 2018 by Vinita
• 220 points

Related Questions In Selenium

0 votes
1 answer

What is Xpath and what are the types of it in Selenium Webdriver?

Hi Piyush, XPath is defined as XML path. It is ...READ MORE

answered May 8 in Selenium by Pratibha
• 2,780 points
111 views
0 votes
1 answer

XPath for the elements with no ID or Name in Selenium Webdriver

Use like this or similar to this: //div[@id="top-level-menu-item-3"]/div[@class="filter-label"] //div[@id="top-level-menu1"] ...READ MORE

answered Apr 17, 2018 in Selenium by Meci Matt
• 9,420 points
1,143 views
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,610 points
224 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,070 points
445 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
793 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
435 views
0 votes
1 answer

What is following-sibling in selenium?

Here, ul has 8 children(8-li) on total.  And, ...READ MORE

answered Jun 1, 2018 in Selenium by Vinita
• 220 points
2,000 views
0 votes
1 answer

preceding-sibling in xpath, Selenium?

Here, ul has 8 children(8-li) on total.  And, ...READ MORE

answered Jun 1, 2018 in Selenium by Vinita
• 220 points
1,545 views