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 in Selenium by anonymous
• 140 points
320 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 by Niroj
• 66,420 points

Related Questions In Selenium

0 votes
2 answers
0 votes
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 in Selenium by Sri
• 2,970 points
15,602 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
3,762 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,744 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
2,728 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 in Selenium by Sri
• 2,970 points
3,086 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 in Selenium by Suhana

edited Jul 6 454 views