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
613 views

2 answers 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
0 votes
some of the controls not have id ,name etc ..

so we have use xpath .
answered Sep 4 by Sri
• 2,970 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, 2019 in Selenium by Pratibha
• 3,690 points
1,280 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,460 points
2,926 views
0 votes
2 answers

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

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

answered Sep 4 in Selenium by Sri
• 2,970 points
883 views
0 votes
2 answers

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,520 points
3,756 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,742 views
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,890 points
2,726 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,081 views
0 votes
2 answers

What is following-sibling in selenium?

Xpath=//*[@type='text']//following::input[2] READ MORE

answered Sep 4 in Selenium by Sri
• 2,970 points
7,381 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
5,681 views