Drake491 Drake491 - 3 months ago 23
HTML Question

Python - Return ID after finding Xpath with Selenium

I'm learning xpath and Selenium, and just successfully found the element I am trying to target. I am searching for a element where data-number = 48264


The HTML I am pulling from looks like this

<li id="pos_4" data-number="48264" class="top-item sellmid">

Now I am trying to return the ID "pos_4". I experimented with the below code, but it was totally wrong.


This returned a long float "0.066103113793198-1". Not sure what this is.


The above returned the text inside the div of the li.

Any suggestions on where to look next? I've done a lot of searching, but couldn't find anything helpful. Thanks!


you can do that by

ele = driver.find_element_by_xpath("//*[@data-number='48264']")

value = ele.get_attribute('id')

print value