Selenium WebDriver Tutorial #13 - What is Relative Locator in Selenium

preview_player
Показать описание
In this Selenium Webdriver Tutorial we will learn about Relative locator in Selenium Webdriver.

Selenium 4 introduced Relative Locators which were previously called as Friendly Locators. Relative locator help to locate elements that are nearby to other elements.

The Available Relative Locators are as follows:

✅ above
✅ below
✅ toLeftOf
✅ toRightOf
✅ near

In Selenium 4, findElement method accepts a new method withTagName() which returns a RelativeLocator.

Help me in spreading the knowledge, please hit LIKE, SHARE and SUBSCRIBE for latest tutorials.

More tutorial playlists below:

❖ TRAININGS ON RCV ACADEMY PORTAL ❖

❖ FOLLOW US ON TWITTER ❖

❖ LIKE US ON FACEBOOK ❖

❖ OUR TUTORIAL WEBSITES ❖

❖ GET MY TRAININGS ON UDEMY ❖
#SeleniumTutorial #SeleniumTraining #TestAutomation #SeleniumWebDriverTutorial #SeleniumWebDriver #SoftwareTesting #RcvAcademy #SoftwareTestingMentor
Рекомендации по теме
Комментарии
Автор

Everything you explains and demos in the channel is crystal clear and easy to understand.
This helps me a lot. Thank you for sharing these invaluable testing skills to us.

rotrose
Автор

it is really helpfull that You explain everything with documentation because now reletive locators works in other way.
For everyone who have problem it should look like this:
WebElement userName =
userName.sendKeys("xyz");
By password =

janskadanowski
Автор

I am new to Selenium and Java. Thanks for your wonderful tutorial. Well explained and easy to follow. Thanks a lot Manish👍😊

gsabhilash
Автор

Master blessings to you and everyone here, i just wanted to comment that by the time i'm watching the video, the sintax changes a little and it would look more or less like this:
"WebElement password =
By userName =
sendKeys("Testing");"
anyway everything is in the documentation but it is not superflous jejejeje
Thank you very much Master.

andergarcia
Автор

Your channel definetly should have more subscribers

felipeluz
Автор

Great course so far. Very well explained. Thanks for your hard work.

rishabhpal
Автор

Selenium WebDriver Tutorial #13 - Relative Locators in Selenium 4 - Notes

1. Introduction:
- Selenium 4 introduces relative locators (previously known as friendly locators) to help locate nearby elements.
- Previous tutorials covered basic element locator strategies and advanced selection using XPath and CSS selectors.

2. Relative Locator Methods:
- Relative locators have several methods: `above`, `below`, `toLeftOf`, `toRightOf`, and `near`.
- These methods find elements based on their position relative to other elements on the page.

3. Adding Selenium 4 Dependency:
- To use relative locators, add Selenium 4 dependency to the project (e.g., in Maven's `pom.xml`).
- For demonstration purposes, use version 4.0.0-alpha-5 (alpha phase).

4. Exploring Relative Locator Methods:
- `above`: Returns the element appearing above the specified element.
- `below`: Returns the element below the specified element.
- `toLeftOf`: Returns the element to the left of the specified element.
- `toRightOf`: Returns the element to the right of the specified element.
- `near`: Returns the element approximately 50 pixels away from the specified element.

5. Using Relative Locator Methods:
- Import the `RelativeLocator` class.
- Locate the reference element for finding nearby elements.
- Use the appropriate method to locate the desired element.
- Example: Use to find an element above the reference element. (older syntax)
- Latest syntax -
WebElement password =
By usernameLocator =

6. Ensuring Reference Element Locatability:
- Ensure unique attributes to locate the reference element.
- Alternatively, use other locators like ID or class name to find the reference element.

JavaScript Function `getBoundingClientRect`:
- Relative locators use `getBoundingClientRect` JavaScript function for calculations.
- Refer to Selenium documentation for further details on this function.

Conclusion:
- Relative locators in Selenium 4 are a valuable addition to WebDriver.
- They allow efficient location of nearby elements.
- Thank you for watching this tutorial on relative locators in Selenium WebDriver.

manoj_mafiosi
Автор

Hi, your tutorials are amazing. Thanks for share them with us 🙏

thiagolopessilva
Автор

Well elaborated courses. Even in paid online classes you wont find such details.

SubbuTube
Автор

Thank you for tutorial. And you explained very simple and direct way. It will be very great helpfull for us if you can make tutorial how to create Java +Selenium +Maven + Junit + Cucumber or this kind of 3 part tools Framework. Maybe already you have it I just starting investigate your webpage. Thank you for all lessons.

zahidukalayev
Автор

Hi in the latest relative locators update this has been discarded, can you please come up with updated video for this. Your videos are really helpful. Thanks

aishwaryathakur
Автор

Hi, your tutorials are very helpful. Thanks.
Could you please provide a reliable demo website/link with a chatbox functionality?

kajaldave
Автор

Thanks for the videos, so interesting. What's the equivalent of the relative locators in RobotFramework. I need to get a child of an element but couldn't. Help pelase

cyrinegassouma
Автор

Hi well oriented session, hats off to you sir 😍👍.
When I used the withTagName method, getting error- undefined method.
Also shows error in the import for that .
Plz give me a solution sir

navamysumethan
Автор

withTagName mai error aarha import bhi kiya hai firbhi



rupalicharpe
Автор

Getting NullPointerException.
Can you please help me out to rectify this issue Sir?

NRNov
Автор

The below line of code for 'Relative Locators' works (you don't have to use/import WebElement), provided you have added the Selenium-java 4.9 dependency in pom file



ajaymandadi
Автор

Hi Sir,

I am using 4.15 selenium dependency, .
I am trying to send text msg to username but I am getting error in "send keys", please look into it. please correct the code.

code::
WebElement password =
By usernameLocator

Error:::
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method sendKeys(String) is undefined for the type RelativeLocator.RelativeBy

at

ajaykumar-gzdf
Автор



Getting error "withTagName"


Please help !!!

md.rifatulhaque
Автор

This didn't work for me in selenium 4.15.0, the following worked though!

WebElement password =

veganforlife