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.

https://account.mail.ru/signup?from=main&rf=auth.mail.ru

Feb 20, 2020 in Selenium by Edureka
• 140 points
4,958 views

2 answers to this question.

0 votes

Hello,

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:

<!DOCTYPE HTML> 

<html> 

<head> 

<title> 

JQuery | Get the text of a span element 

</title> 

<script src = 

"https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> 

</script> 

</head> 

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

<h1 style = "color:green;" > 

Edureka

</h1> 

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

This is text of Span element. 

</span> 

<br><br> 

<button> 

Click Here 

</button> 

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

</p> 

<script> 

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

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

$('#GFG_DOWN').text($val); 

});  

</script> 

</body> 

</html>  

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, 2020 by Niroj
• 82,840 points
0 votes
Do you just want to select the option?
answered Feb 27, 2020 by Etl
• 170 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 14, 2018 in Selenium by king_kenny
• 3,710 points
1,032 views
0 votes
1 answer
0 votes
6 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
76,233 views
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,910 points
7,275 views
0 votes
2 answers

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,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
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,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
+2 votes
1 answer

How to fetch the text of a web element where the text is split in 2 lines?

Hello, You want to use a non-breaking space ...READ MORE

answered May 28, 2020 in Selenium by Niroj
• 82,840 points
4,417 views
0 votes
1 answer

How to Handle alerts like Irctc alert in selenium?

Hello  karthik, Handling alerts manually is a tedious task. ...READ MORE

answered Jun 29, 2020 in Selenium by Niroj
• 82,840 points
2,889 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP