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
142 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
• 33,440 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

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

Yes, its very much possible. You just ...READ MORE

answered May 8, 2018 in Selenium by king_kenny
• 3,710 points
13,152 views
0 votes
1 answer
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
2,873 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,225 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,338 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 1 day ago in Selenium by Suhana

edited 1 day ago 63 views
0 votes
2 answers

how to select text by span class

Do you just want to select the ...READ MORE

answered Feb 27 in Selenium by Etl
• 160 points
127 views