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,010 points
72 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,590 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,280 points
3,757 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,400 points
963 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,280 points
1,161 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,590 points
2,497 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,050 points
247 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
618 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
235 views
0 votes
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 20, 2018 in Selenium by king_kenny
• 3,590 points
98 views