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

Поделиться
HTML-код
  • Опубликовано: 2 дек 2024

Комментарии • 46

  • @rotrose7531
    @rotrose7531 3 года назад +4

    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.

  • @janskadanowski9276
    @janskadanowski9276 2 года назад +10

    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");

    • @Alyoms_kitchen
      @Alyoms_kitchen Год назад

      Thank you!! Helpful

    • @InduVenu
      @InduVenu 9 месяцев назад

      Thanks for the update. Helpful.

  • @gsabhilash
    @gsabhilash 4 года назад +5

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

    • @softwaretestingmentor
      @softwaretestingmentor  4 года назад +1

      Hi Abhilash, Thank you very much! I am glad you liked them. Regards,Manish

  • @felipeluz1333
    @felipeluz1333 4 года назад +3

    Your channel definetly should have more subscribers

  • @manoj_mafiosi
    @manoj_mafiosi Год назад +3

    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.

    • @mounikams7688
      @mounikams7688 Год назад

      Thank you for your explanation. Could you please let me how should sendkeys in latest syntax of Relative locators

  • @andergarcia1115
    @andergarcia1115 Год назад +3

    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.

  • @rishabhpal95
    @rishabhpal95 3 года назад +2

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

  • @SubbuTube
    @SubbuTube 3 года назад +1

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

  • @thiagolopessilva
    @thiagolopessilva Год назад +1

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

  • @aishwaryathakur6658
    @aishwaryathakur6658 2 года назад +1

    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

    • @janskadanowski9276
      @janskadanowski9276 2 года назад

      WebElement userName = driver.findElement(By.tagName("input"));
      userName.sendKeys("xyz");
      By password = RelativeLocator.with((By.tagName("input"))).below(userName);
      driver.findElement(password).sendKeys("123qwe");

  • @zahidukalayev4404
    @zahidukalayev4404 2 года назад

    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.

  • @kajaldave8607
    @kajaldave8607 2 года назад

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

  • @cyrinegassouma4598
    @cyrinegassouma4598 3 года назад

    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

  • @NRNov16
    @NRNov16 2 года назад

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

  • @navamysumethan7735
    @navamysumethan7735 2 года назад

    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

    • @purvidholakia3570
      @purvidholakia3570 2 года назад

      I am getting same error with selenium version 4.3.0. Please sir reply.

  • @rupalicharpe7043
    @rupalicharpe7043 2 года назад +1

    withTagName mai error aarha hai.....q? import bhi kiya hai firbhi
    driver.findElement(withTagName("input").above(password)).sendKeys("Testing");

    • @umeshraut878
      @umeshraut878 2 года назад

      any solution you got?

    • @md.rifatulhaque7047
      @md.rifatulhaque7047 2 года назад

      By email = RelativeLocator.withTagName("input").above(By.id("password"));

    • @ShivaYadav-zt6tn
      @ShivaYadav-zt6tn 2 года назад +2

      driver.findElement(with(By.tagName("input")).above(password)).sendKeys("Shiv@Yadav");

    • @namangaur19
      @namangaur19 Год назад

      @@ShivaYadav-zt6tn Thanks bro, it worked

  • @ajaymandadi5200
    @ajaymandadi5200 Год назад

    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");

  • @vivek4531
    @vivek4531 Год назад

    jagpreet g

  • @ajaykumar-gz8df
    @ajaykumar-gz8df Год назад

    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)

  • @md.rifatulhaque7047
    @md.rifatulhaque7047 2 года назад

    driver.findElement(withTagName("input").above(password)).sendKeys("Testing");
    Getting error "withTagName"
    Please help !!!

    • @janskadanowski9276
      @janskadanowski9276 2 года назад

      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

    • @sk_bhuvanesh
      @sk_bhuvanesh 2 года назад

      same problem

    • @ShivaYadav-zt6tn
      @ShivaYadav-zt6tn 2 года назад +1

      driver.findElement(with(By.tagName("input")).above(password)).sendKeys("Shiv@Yadav");

    • @hammadshafiq4962
      @hammadshafiq4962 Год назад

      @@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

  • @veganforlife4699
    @veganforlife4699 Год назад +1

    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");

    • @dmitryneve1140
      @dmitryneve1140 8 месяцев назад

      it took me 4 hours to find the solution before I decided to read the comments and found yours.

    • @manaligb
      @manaligb 5 месяцев назад

      @@dmitryneve1140 what was the solution for this , pls give in detail what o do.

    • @dmitryneve1140
      @dmitryneve1140 5 месяцев назад

      @@manaligb it was exactly how it is described above.

    • @manaligb
      @manaligb 5 месяцев назад

      @@dmitryneve1140 Yes, There was a mistake made by me in keeping the parentheris so was the error occuring. Thankyou so much.