-1

In below screenshot you can see that I am trying to identify the password field with a valid xpath:

(.//*[@id='loginForm']/div/div/div/div/input)

No elements is identified but if I use the inspect element button and find any element randomly and then use the above xpath expression it is working.

Screenshot 1
enter image description here

Screenshot 2
enter image description here

Sandeep
  • 1,504
  • 7
  • 22
  • 32
dolittle
  • 310
  • 1
  • 5
  • 13
  • Password element is in same window?? If not try to switch window. After that you can easily locate the element. – Deepesh kumar Gupta May 06 '16 at 06:50
  • 1
    Where is the mentioned screenshot? Provide `html` code and code you used to find element – Andersson May 06 '16 at 06:53
  • also there is same question you posted an hour ago http://stackoverflow.com/questions/37064349/unable-to-find-an-element-with-a-vaid-xpath-expression You should edit previous question instead of posting it again! – Andersson May 06 '16 at 07:12
  • password element is in the same window only – dolittle May 06 '16 at 08:40

2 Answers2

1

I got your point.

The thing is if you start the firepath and pasted

  //*[@id='loginForm']/div/div1/div/div/input

above xpath, it tried to find that element if that is available in default or main page. If your element is inside any iframe then it will not able to find it.

If you inspect that element or any other near by, if they are inside same frame then your firepath is inside or focus on to that frame. If pasted your above xpath then it will able to find the element because you alreay in focus of that frame.

As per screen if you observe firepath left side, you are able to find some thing like iframe#iframe means your firepath is in focus to that frame and elements in that frame able to find by pasting.

At the time of starting the firepath it may like top window or widows and you pasted any element available in frame, then it is expected that it will not able to find it.

I hope you got it.

Thank You, Murali

murali selenium
  • 3,847
  • 2
  • 11
  • 20
  • then what is the solution how can i use the xpath path expression in my code – dolittle May 06 '16 at 08:23
  • You can use same xpath but before that you need to switch to frame as that element is inside the frame. http://stackoverflow.com/questions/10879206/how-to-switch-between-frames-in-selenium-webdriver-using-java – murali selenium May 06 '16 at 08:31
  • the problem is i am unable to find elements in that particular web portal – dolittle May 06 '16 at 08:39
  • hmm.. probably on seeing the page and selenium code.. i can help you. you can try by selenium ide. just record and run..if it runs then check your code where is the issue – murali selenium May 06 '16 at 08:42
0

As murali said element was present inside IFRAME i changed the focus to iframe now it is working properly

dolittle
  • 310
  • 1
  • 5
  • 13