-2

I use xpath of Chrome extension to get element's xpath.

span[@id='txt_btn_continue']

It works on the browser but not in code.The error i get is

Unable to locate element: 
{"method":"xpath","selector":"//*[@id='txt_btn_continue']"}

I cannot figure out the reason. Anyone could help me? Thanks in advance.

Return-1
  • 2,329
  • 3
  • 21
  • 56
Rogers Shu
  • 93
  • 1
  • 1
  • 5
  • You have noticed that the two xpaths are not the same (span vs. *)? – Florian Albrecht May 15 '17 at 07:49
  • Without further infos, nobody can answer this. The selector looks valid. – f1sh May 15 '17 at 07:49
  • can you share some html code or the whole website? What error you get? – metar May 15 '17 at 07:49
  • 1
    @FlorianAlbrecht the ``*`` covers the ``span``, so that's not an issue. – f1sh May 15 '17 at 07:50
  • @f1sh Well, without further info, it *could* be an issue and should at least be clarified. – Florian Albrecht May 15 '17 at 07:51
  • @FlorianAlbrecht since ``*`` is less specific than ``span``, the xpath could find _more_ elements, but none are found. – f1sh May 15 '17 at 07:59
  • This could be [timing issue](http://www.guru99.com/implicit-explicit-waits-selenium.html) or [element could be located inside an `iframe`](http://stackoverflow.com/questions/9942928/how-to-handle-iframe-in-webdriver). Check both options – Andersson May 15 '17 at 08:01
  • @f1sh from a technical POV I totally agree and never said that * won't work. But as the two selectors differ, maybe the OP has a problem somewhere else (wrong code branch)? They should just clarify, that's all. – Florian Albrecht May 15 '17 at 08:01
  • If you have the id of and element why don't to try using ID itself ? – NarendraR May 15 '17 at 08:17
  • 1
    answer of such question has already been answered couple of time in this forum, please search them before posting it. – Gaurang Shah May 15 '17 at 11:58
  • @RogersShu Your question is unclear/invalid `use xpath of Chrome extension to get element's xpath`. Can you rephrase your Question with the exact requirement please? Thanks – undetected Selenium May 15 '17 at 12:53

1 Answers1

1

Potential reasons:

  • your element is in a frame and you need to switch to it before search.
  • element is hidden or disabled and in the code you need to perform exactly the same steps before selecting element which you do manually (in the test)
  • the page is not fully loaded at the moment you search for the element.
IKo
  • 4,998
  • 8
  • 34
  • 54