Hey there! any question in your mind? Ask It Now!.

Popular Categories

How to use xpath with span in selenium?

+1 vote
asked in Software Testing by Kaperly (1,610 points)
edited by Kaperly
I am new in selnium and i want to know how to make xpath with span?

1 Answer

+1 vote
answered by CaptSaltyJack (1,140 points)
selected by Kaperly
Best answer

its very simple eigther you should downlod a plugin xpath viewer in firefox of you can get it from selenium ide plugin.

If you want more info about xpath see this : 

Useful XPATH patterns


Not yet written - locate elements based on the text content of the node.


Many sites use dynamic values for element’s id attributes, which can make them difficult to locate. One simple solution is to use XPath functions and base the location on what you do know about the element. For example, if your dynamic ids have the format <input id="text-12345" /> where 12345 is a dynamic number you could use the following XPath://input[starts-with(@id, 'text-')]


If an element can be located by a value that could be surrounded by other text, the contains function can be used. To demonstrate, the element <span class="top headingbold"> can be located based on the ‘heading’ class without having to couple it with the ‘top’ and ‘bold’ classes using the following XPath: //span[contains(@class, 'heading')]. Incidentally, this would be much neater (and probably faster) using the CSS locator strategycss=span.heading


Not yet written - locate elements based on their siblings. Useful for forms and tables.

Starting to use CSS instead of XPATH

Locating elements based on class

In order to locate an element based on associated class in XPath you must consider that the element could have multiple classes and defined in any order. However with CSS locators this is much simpler (and faster).

  • XPath: //div[contains(@class, 'article-heading')]
  • CSS: css=div.article-heading


commented by Kaperly (1,610 points)
thanks i have downloaded xpath viewer it works.

Related Questions

+1 vote
1 answer 698 views

Not a Member yet?

Ask to Folks Login

My Account
327 Folks are online
0 members and 327 guest online
Your feedback is highly appreciated