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

+2 votes

Hi,

The HTML looks like the following:

<div class="ReviewAndRatingsstyles__AverageReviewWrapper-sc-1nxmeoo-5 kWDiZc">

         <span class="ReviewAndRatingsstyles__AverageReviewText-sc-1nxmeoo-6 jVFGfi">

              "4.2"

             " / 5"

        </span>

</div>

I need to capture the text 4.2/5.

Thank you.

May 28, 2020 in Selenium by anonymous
• 140 points
3,971 views

1 answer to this question.

0 votes

Hello,

You want to use a non-breaking space in your HTML markup  so use &nbsp; instead of a normal space.

HTML

"4.2 &nbsp;/5"

Or you can try this

CSS

.ReviewAndRatingsstyles__AverageReviewText-sc-1nxmeoo-6 jVFGfi {
    white-space: ReviewAndRatingsstyles__AverageReviewText-sc-1nxmeoo-6 jVFGfi;
}

HTML

<span class="ReviewAndRatingsstyles__AverageReviewText-sc-1nxmeoo-6 jVFGfi">4.2</span>
<span class="ReviewAndRatingsstyles__AverageReviewText-sc-1nxmeoo-6 jVFGfi">/5</span>

Any element with white-space: ReviewAndRatingsstyles__AverageReviewText-sc-1nxmeoo-6 jVFGfi stays on one line.

Hope this works!!

answered May 28, 2020 by Niroj
• 82,880 points

Related Questions In Selenium

0 votes
2 answers

Is there any way to get the text of a web element using Selenium Webdriver?

use gettext() in java : string lableText = ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
8,121 views
+1 vote
2 answers

Is it possible to manually set the attribute value of a Web Element using Selenium?

WebDriver driver; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id123').setAttribute('attr', ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
26,639 views
0 votes
1 answer
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
12,578 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
8,559 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
6,606 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,506 views
0 votes
3 answers

How to stop a page loading from selenium in chrome?

Hi Savan, Setting the pageLoadStrategy capability to none. Then wait for ...READ MORE

answered Jul 7, 2020 in Selenium by Suhana

edited Jul 7, 2020 6,398 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