-2

I have a registration page.

In my test, I'm trying to register without a first name. Pressing the register button should display the a 'Required' notification label.

You can see the structure in the attached screenshot. I tried to get the text from the id 'firstName' by xpath, id, etc. It failed to locate this object.

My latest attempt:

String test = driver.findElement(By.id("'firstName'/descendant::td[@class='alert alert-danger']")).getText();`

What am I missing?

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Nir Ortal
  • 77
  • 12
  • i think by By.id is the wrong method try By.css, also the div with class alert is NOT a descendant of #firstname – b3nc1 Apr 16 '18 at 15:51
  • 1
    Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Apr 16 '18 at 18:13
  • Tried that - but found out that the paste is not exactly like the original and edit it to be like the original is not so simple and in the end, receive a wrong answer from you guys. Thanx for the comment! – Nir Ortal Apr 17 '18 at 07:11

1 Answers1

3

Try By.cssSelector("#firstName + registration-control-messages > div.alert")

The By you are using is not correct.

JeffC
  • 22,180
  • 5
  • 32
  • 55
Grasshopper
  • 8,908
  • 2
  • 17
  • 32
  • Simplified your CSS selector. You had a lot of stuff in there that was using more of an XPath syntax. – JeffC Apr 16 '18 at 18:16