Need some advise on the preferred element locators with Selenium WebDriver

0 votes
Even though I am aware of how to search for the different elements on a page in Selenium Webdriver, i'm not sure which are the best techniques and want an idea of the hierarchy for element locators for web page testing with Selenium. Such as Xpath vs cssSelector vs ID vs others....knowing this will let me build my test cases the correct way so that they run as quickly as possible.
Apr 13, 2018 in Selenium by kappa3010
• 2,090 points
1,375 views

1 answer to this question.

0 votes
Well let's not call it "Hierarchy". But, yea there are certain techniques which are more preferred.
For simplicity sake, you can use By.iD() or By.name().
But a lof times, these locators might not be supported by the HTML tags in all web pages.

So, at such times you might want to use By.xpath() and By.cssSelector().
XPath is the defacto standard for locating elements...but its a little complicated and might require you to use tools like Firebug or Firepath to get the XPath. cssSelector is the other best option. These two techniques will help you locate the elements guaranteed. No doubts.

Besides them you can use other techniques like By.className() or By.tagName() or By.linkText() or By.partialLinkText(). These should certainy work.
answered Apr 13, 2018 by king_kenny
• 3,710 points

Related Questions In Selenium

0 votes
1 answer

Using gettext() method for the specific element using Selenium WebDriver

Mistake is that u r printing the ...READ MORE

answered Apr 10, 2018 in Selenium by Vardy
• 2,360 points
28,716 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,371 views
0 votes
1 answer

Searching for the element with   symbol in selenium

Use Below: //div[@class='Tips' and text()='\u00a0'] READ MORE

answered Apr 20, 2018 in Selenium by Vardy
• 2,360 points
9,323 views
0 votes
1 answer

How do i click on <input type=file> on any browser if i'm testing with Selenium Webdriver?

Does not matter which OS or which ...READ MORE

answered Apr 29, 2018 in Selenium by king_kenny
• 3,710 points
10,811 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,670 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,140 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,219 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,872 views
+1 vote
2 answers
0 votes
1 answer

Need to scroll down for locating an Element with Selenium

There are a couple of options for ...READ MORE

answered Apr 21, 2018 in Selenium by king_kenny
• 3,710 points
12,946 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