-1

Hi I am trying to access a xapth which i have verified from developer tools and is correct. But at run time i am selenium is unable to locate it and getting element not visible exception.

My Xptah : //div[contains(text(),'Current Status of Python')]

i could not find any iframe here but still at run time it fails to locate the element.

One thing i observed that in dev tool if i directly paste my xpath then there also it unable to locate it i have to click on the source of element( div tag) then my xpath works. Not sure what is this behavior.

enter image description here

QASateesh
  • 27
  • 3
  • That is not a normal text, that is a text node. You should use text to locate this particular element, it' better if you could use other web element to locate this web element. – cruisepandey Nov 13 '21 at 07:15

1 Answers1

0

In XPath 1.0, the expression //div[contains(text(),'Current Status of Python')] selects any div whose first text node contains the relevant string. In your document, this string appears in the second text node of the div.

This is one of many examples where text() is being used incorrectly. It's almost invariably better to write //div[contains(.,'Current Status of Python')].

(XPath 2.0 would give you an error for contains(text(), '...') if it finds an element with more than one text node.)

Michael Kay
  • 156,231
  • 11
  • 92
  • 164