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
1,814 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, 2020 by Sri
• 3,190 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 9, 2019 in Selenium by Pratibha
• 3,690 points
5,387 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
7,465 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, 2020 in Selenium by Sri
• 3,190 points
2,937 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,500 points
13,772 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,187 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,910 points
7,263 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 3, 2020 in Selenium by Sri
• 3,190 points
7,901 views
0 votes
2 answers

What is following-sibling in selenium?

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

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
11,817 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
14,316 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP