0
driver.get("https://urlk/my-account/");
WebElement password = driver.findElement(By.id("password"));
driver.findElement(RelativeLocator.with(By.tagName("input")).above("password")).sendKeys("hi");

.above in the code is highlighted in red and shows the following when I hover: the method above(WebElement) in the type relativelocator.relativeby is not applicable for the argument (string)

I am working on selenium locator tutorial.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
taerese
  • 53
  • 5

1 Answers1

0

You were almost there. above expects a WebElement but not the string "password".


Solution

So effectively your line of code will be:

WebElement password = driver.findElement(By.id("password"));
driver.findElement(RelativeLocator.with(By.tagName("input")).above(password)).sendKeys("hi");

In a single line:

driver.findElement(RelativeLocator.with(By.tagName("input")).near(driver.findElement(By.id("password")))).sendKeys("hi");

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Why was the quotation mark "" missing in .above(password)) , also I noticed that while the URL actually opened, the sendkeys value "hi" is not passed in the form. I have also test with URL: Facebook.com – taerese Jul 10 '23 at 21:11
  • @taerese _Why was the quotation mark "" missing in .above(password))_: See at the beinging of the answer _`above` expects a WebElement but not any string_ – undetected Selenium Jul 10 '23 at 21:24