Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14155

Finding An Element Based off a partial ID using Selenium in Python

$
0
0

I'm trying to get some weather data off of a website using selenium. On the html file they look something like this:

<div id="tdatmo1-FFrad6Noeud-20240225-0700" name="tdatmo1-FFrad6Noeud-20240225-0700" class="container_value " .><div class='box-offset'>10</div></div><div id="tdatmo1-FFrad6Noeud-20240225-0654" name="tdatmo1-FFrad6Noeud-20240225-0654" class="container_value " .><div class='box-offset'>9</div></div><div id="tdatmo1-FFrad6Noeud-20240225-0648" name="tdatmo1-FFrad6Noeud-20240225-0648" class="container_value " .><div class='box-offset'>7</div></div>

The first parts of the IDs are always the same, but the latter half changes based on the time/day.

I figured I could use driver.find_elements(By.ID, "tdatmo1-FFrad6Noeud") but that doesn't seem to work. I also know of By.XPATH and PARTIAL_LINK_TEXT, but I am not sure if they would work in my case.I looked at the solutions hereand tried

driver.find_element(By.XPATH, "//*[contains(@id, 'tdatmo1-FFrad6Noeud')]")

and that gave me

<selenium.webdriver.remote.webelement.WebElement (session="007ad7b2-c5ba-46a8-8f5b-cbe0ea396b55", element="1c616c23-d457-4799-9c20-5a831d2895f1")>

I'm not sure if that's giving me what I want, and it's definitely not in a form that I can understand.


Viewing all articles
Browse latest Browse all 14155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>