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 in Selenium by Edureka
• 140 points
146 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 by Niroj
• 43,100 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
121 views
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
31,812 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,890 points
3,750 views
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
3,120 views
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,890 points
2,353 views
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,890 points
2,504 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 in Selenium by Niroj
• 43,100 points
167 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 in Selenium by Niroj
• 43,100 points
86 views