Search code examples
kotlinselenide

Kotlin\Java - String like "$1" to number


So I'm writing automated tests in Kotlin + Selenide for the pricing. I have 59 items in the cart. Each item is coded like this:

<div class="review-submit-list-total"><!-- react-text: 5 -->$<!-- /react-text --><!-- react-text: 6-->33.00<!-- /react-text --></div>

I get the price by val price1 = $(#some-locator).text it returns price as "$33.00". I need to get all the prices and then calculate them.

Would appreciate any ideas. Thanks.


Solution

  • Found an answer by myself:

    val price1 = "$3999.00"     
    val p1 = price1.replace("$", "")
    val p2 = p1.toFloat()