exec85
exec85

Reputation: 487

how to get div text with python selenium?

How can I get the text "950" from the div that has neither a ID nor a Class with python selenium?

<div class="player-hover-box" style="display: none;">
    <div class="ps-price-hover">
        <div><img class="price-platform-img-hover"></div>
        <div>950</div>
    </div>

I dont know how I could access this div and its text.

Upvotes: 1

Views: 1276

Answers (1)

Prophet
Prophet

Reputation: 33361

In case player-hover-box is an unique class name you can use the following command

price = driver.find_element_by_xpath('//div[@class="player-hover-box"]/div/div[2]').text

In case there are more products on that page with the similar HTML structure your XPath locator should contain some unique relation to some other element.

Upvotes: 1

Related Questions