How can I locate web elements from a web page using Selenium Webdriver?

0 votes
I want to know how web elements can be located or selected from a webpage using Selenium Webdriver?
May 28 in Selenium by Dushyant
26 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hey @Dushyant, Locating elements in WebDriver is done by using the method “findElement(By.locator())“. You can use following Locators to identify and locate the web elements from a web page in Selenium Webdriver:

  1. ID Locator: ID’s are unique for each element so it is common way to locate elements using ID Locator. Also ID locators are the fastest and safest locators out of all locators. For eg. findElement(By.id("IdName"))

  2. Name Locator: Name locators are also used to identify the elements on our webpage. Locating elements using Name is same as locating elements using ID locator. These are not unique on a page, so test may fail, if another element with the same Name locator is present on the web page. For eg. findElement(By.name("Name"))

  3. Class Name Locator: Class Name locator gives the element which matches the values specified in the attribute name “class”. For eg. findElement(By.className("Element Class"))

  4. Tag Name Locator: Tag Name locator is used to find the elements matching the specified Tag Name. It is very helpful when we want to extract the content within a Tag. For eg. findElement(By.tagName("HTML Tag Name"))

  5. Link Text Locator: If there are multiple elements with the same link text then the first one will be selected. This Link Text locator works only on links (hyperlinks) so it is called as Link Text locator. For eg. findElement(By.linkText("LinkText"))

  6. Partial Link Text: In some situations, we may need to find links by a portion of the text in a Link Text element. it contains. In such situations, we use Partial Link Text to locate elements. For eg. findElement(By.partialLinkText("partialLinkText"))

  7. CSS Selector Locator: CSS selectors makes the execution of script faster compared to XPath locator. This locator is always the best way to locate elements on the page. Following are the some of the mainly used formats of CSS Selectors. For eg. findElement(By.cssSelector(tag#id)), findElement(By.cssSelector(tag.class))

  8. XPath Locator: XPath is designed to allow the navigation of XML documents, with the purpose of selecting individual elements, attributes, or some other part of an XML document for specific processing. XPath produces reliable locators but in performance wise it is slower compared to CSS Selector. For eg. findElement(By.xpath("XPath"))

answered May 28 by Shreya

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,210 points
288 views
0 votes
1 answer
0 votes
1 answer
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
135 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
527 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
129 views
0 votes
1 answer

How to mouse hover on a web element using Selenium WebDriver?

Hello Nitin, to automate mouse hovering over ...READ MORE

answered May 7 in Selenium by Anvi
• 7,160 points
21 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.