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.
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 = driver.findElement(By.tagName("input")); userName.sendKeys("xyz"); By password = RelativeLocator.with((By.tagName("input"))).below(userName); driver.findElement(password).sendKeys("123qwe");
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 `RelativeLocator.withTagName("tagname").above(referenceElement)` to find an element above the reference element. (older syntax) - Latest syntax - WebElement password = driver.findElement(By.id("password")); By usernameLocator = RelativeLocator.with(By.tagName("input")).above(password); 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.
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 = driver.findElement(By.id("password")); By userName = RelativeLocator.with(By.tagName("input")).above((password)); driver.findElement(userName).. sendKeys("Testing");" anyway everything is in the documentation but it is not superflous jejejeje Thank you very much Master.
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
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.
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
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
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 driver.findElement(RelativeLocator.with(By.tagName("input")).above(By.id("password"))).sendKeys("standard_user"); driver.findElement(RelativeLocator.with(By.tagName("input")).above(By.id("login-button"))).sendKeys("secret_sauce");
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 = driver.findElement(By.id("password")); By usernameLocator =RelativeLocator.with(By.tagName("input")).above(password).sendKeys("standard_user"); Error::: Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method sendKeys(String) is undefined for the type RelativeLocator.RelativeBy at practice.Locators.main(Locators.java:33)
WebElement userName = driver.findElement(By.tagName("input")); userName.sendKeys("xyz"); By password = RelativeLocator.with((By.tagName("input"))).below(userName); driver.findElement(password).sendKeys("123qwe"); everything is in documentation :D
@@ShivaYadav-zt6tn WebElement password = driver.findElement(By.id("password")); driver.findElement(with(By.tagName("input")).above(password)).sendKeys("Shiv"); using this no error appears but when the browser open no action appear against send keyword. I want to learn selenium if anyone can help please let me know
This didn't work for me in selenium 4.15.0, the following worked though! WebElement password = driver.findElement(By.id("password")); driver.findElement(RelativeLocator.with(By.tagName("input")).above(password)).sendKeys("Testing");
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.
You're very welcome!
Keep watching.
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 = driver.findElement(By.tagName("input"));
userName.sendKeys("xyz");
By password = RelativeLocator.with((By.tagName("input"))).below(userName);
driver.findElement(password).sendKeys("123qwe");
Thank you!! Helpful
Thanks for the update. Helpful.
I am new to Selenium and Java. Thanks for your wonderful tutorial. Well explained and easy to follow. Thanks a lot Manish👍😊
Hi Abhilash, Thank you very much! I am glad you liked them. Regards,Manish
Your channel definetly should have more subscribers
Hi Felipe, Thank you for appreciation. Regards, Manish
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 `RelativeLocator.withTagName("tagname").above(referenceElement)` to find an element above the reference element. (older syntax)
- Latest syntax -
WebElement password = driver.findElement(By.id("password"));
By usernameLocator = RelativeLocator.with(By.tagName("input")).above(password);
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.
Thank you for your explanation. Could you please let me how should sendkeys in latest syntax of Relative locators
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 = driver.findElement(By.id("password"));
By userName = RelativeLocator.with(By.tagName("input")).above((password));
driver.findElement(userName).. sendKeys("Testing");"
anyway everything is in the documentation but it is not superflous jejejeje
Thank you very much Master.
Great course so far. Very well explained. Thanks for your hard work.
Well elaborated courses. Even in paid online classes you wont find such details.
Hi Subbu, thank you, I am glad my work is helpful. Regards, Manish
Hi, your tutorials are amazing. Thanks for share them with us 🙏
You're very welcome.
Keep watching for more videos and tutorials.
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
WebElement userName = driver.findElement(By.tagName("input"));
userName.sendKeys("xyz");
By password = RelativeLocator.with((By.tagName("input"))).below(userName);
driver.findElement(password).sendKeys("123qwe");
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.
Hi, your tutorials are very helpful. Thanks.
Could you please provide a reliable demo website/link with a chatbox functionality?
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
Getting NullPointerException.
Can you please help me out to rectify this issue Sir?
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
I am getting same error with selenium version 4.3.0. Please sir reply.
withTagName mai error aarha hai.....q? import bhi kiya hai firbhi
driver.findElement(withTagName("input").above(password)).sendKeys("Testing");
any solution you got?
By email = RelativeLocator.withTagName("input").above(By.id("password"));
driver.findElement(with(By.tagName("input")).above(password)).sendKeys("Shiv@Yadav");
@@ShivaYadav-zt6tn Thanks bro, it worked
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
driver.findElement(RelativeLocator.with(By.tagName("input")).above(By.id("password"))).sendKeys("standard_user");
driver.findElement(RelativeLocator.with(By.tagName("input")).above(By.id("login-button"))).sendKeys("secret_sauce");
jagpreet g
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 = driver.findElement(By.id("password"));
By usernameLocator =RelativeLocator.with(By.tagName("input")).above(password).sendKeys("standard_user");
Error:::
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method sendKeys(String) is undefined for the type RelativeLocator.RelativeBy
at practice.Locators.main(Locators.java:33)
driver.findElement(withTagName("input").above(password)).sendKeys("Testing");
Getting error "withTagName"
Please help !!!
WebElement userName = driver.findElement(By.tagName("input"));
userName.sendKeys("xyz");
By password = RelativeLocator.with((By.tagName("input"))).below(userName);
driver.findElement(password).sendKeys("123qwe");
everything is in documentation :D
same problem
driver.findElement(with(By.tagName("input")).above(password)).sendKeys("Shiv@Yadav");
@@ShivaYadav-zt6tn WebElement password = driver.findElement(By.id("password"));
driver.findElement(with(By.tagName("input")).above(password)).sendKeys("Shiv"); using this no error appears but when the browser open no action appear against send keyword. I want to learn selenium if anyone can help please let me know
This didn't work for me in selenium 4.15.0, the following worked though!
WebElement password = driver.findElement(By.id("password"));
driver.findElement(RelativeLocator.with(By.tagName("input")).above(password)).sendKeys("Testing");
it took me 4 hours to find the solution before I decided to read the comments and found yours.
@@dmitryneve1140 what was the solution for this , pls give in detail what o do.
@@manaligb it was exactly how it is described above.
@@dmitryneve1140 Yes, There was a mistake made by me in keeping the parentheris so was the error occuring. Thankyou so much.