-3

I am learning selenium Xpath. what are the different ways of Xpath ? what is the difference between //span and//*?

  • 4
    What rrsearch have you done so far? What google says? – dzieciou Nov 16 at 12:51
5

The difference is that //* selects any element and //span select elements that are within a span tag

2

// means that you look for the elements wherever they are ander the current node of xml tree. In your case you start from // which means that the "current node" is the root node.

Then you specify which element you would like to search. span is just a concrete node name while * is a mask accepting any node name. So in your case //span means "take all nodes with name span wherever they are in document hierarchy. //* means take all nodes of the document.

1
  1. Open any website and click f12, and click the elements tab: enter image description here
  2. Now click ctrl+F, you can see a text field where you can search the element using XPath,text or CSS

enter image description here

  1. Now click on some element and then give then type the locators //span, and //* in the text field, see what's happening

enter image description here

Answer:

  • '//' means that look for the element from 'Current node'
  • //span looks for elements with tag 'span', so on searching you will find only elements with tag name span'
  • //* looks for elements with any tag, so it will literally find all the tags in the webpage

Note:

Searching "//span" might find the non-span tag in the chrome inspect element, this is because the search field also supports normal text search in the DOM. But in selenium, it will find only tags with name 'Span'

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.