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
582 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,540 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,010 points
5,108 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 3, 2020 in Selenium by Sri
• 3,010 points
17,373 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,520 points
4,359 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,010 points
5,280 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,890 points
3,159 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 2, 2020 in Selenium by Sri
• 3,010 points
3,680 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 6, 2020 in Selenium by Suhana

edited Jul 6, 2020 1,061 views