how to select text by span class

0 votes

Please help me select text from span class i will attach screenshot and link. need select country 

i am new in selenium.

Thank you.

Feb 20 in Selenium by Edureka
• 140 points

2 answers to this question.

0 votes


For a given HTML document and the task is to get the text of a <span> tag using JQuery.

 you can Use jQuery text() method():This method is used to set or return the text content of specified elements. If this method is used to return content, it returns the text content of all matched elements (HTML tags will be removed). If this method is used to set content, it overwrites the content of all matched elements.

Let me give you the sample code how text() works so that you can have reference:





JQuery | Get the text of a span element 


<script src = 




<body style = "text-align:center;" id = "body"> 

<h1 style = "color:green;" > 



<span id="GFG_Span" style = "font-size: 15px; font-weight: bold;"> 

This is text of Span element. 




Click Here 


<p id="GFG_DOWN" style="color:green;font-size:20px;font-weight:bold;"> 



$('button').on('click', function() { 

var $val = $('#GFG_Span').text(); 






Tips: Provide each span class with their id to select and associate with the clicks.

Thank you!! Hope this will be helpful to you

answered Feb 24 by Niroj
• 8,220 points
0 votes
Do you just want to select the option?
answered Feb 27 by Etl
• 160 points

Related Questions In Selenium

0 votes
1 answer

How to select an Object by its class in Selenium?

When it comes to Selenium, XPath will ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,710 points
0 votes
1 answer
0 votes
3 answers

How to get text found between span – selenium

The text "Search Zone" is not part ...READ MORE

answered Feb 28, 2019 in Selenium by Trying to Figure
0 votes
1 answer

How to click a span with given text using Selenium Python

If ALL_USA is subject to change, then ...READ MORE

answered Jul 26, 2018 in Selenium by Samarpit
• 5,870 points
0 votes
1 answer

How to print text from a list of all web elements with same class name in Selenium?

@Rajni, following test case is somewhat similar ...READ MORE

answered Jun 20, 2019 in Selenium by Avantika
+1 vote
1 answer

How to get typed text from a textbox by using Selenium Webdriver?

Hey Ashmita, to get the typed text ...READ MORE

answered Jun 24, 2019 in Selenium by Abha
• 27,800 points
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,870 points