GLADOS
GLADOS

Reputation: 53

Extract id of the div using selenium in Python

Can someone help me to extract the id text (the underline one in the below-attached image) from this link: https://opennem.org.au/facilities/au/?selected=DEIBDL&status=operating,committed,commissioning,retired

To get the right on the item in any of the items in the table and inspect.

enter image description here

I knew how to extract the table text but I want the id text which I underlined

Upvotes: 0

Views: 242

Answers (1)

Prophet
Prophet

Reputation: 33361

The selected element can be located by this XPath

//div[@class='card is-selected']

Or this CSS Selector

div.is-selected

So, you can use this Selenium code to extract the id attribute value:

id = driver.find_element(By.XPATH,"//div[@class='card is-selected']").get_attribute("id")

But this will give you the id appearing on the dev tools, this is not always the text you see as a user on the page. To get the text user sees you will need this:

name = driver.find_element(By.CSS_SELECTOR,"div.is-selected .station-name").text

This can be done woth XPath as well

Upvotes: 1

Related Questions