Python Forum

Full Version: Selenium returning web element instead of desired text
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I just started web scrapping and decided to play around with Selenium. Below is the code I wrote to just login to the website and attempt to grab some data.

from selenium import webdriver

driver = webdriver.Chrome(r"C:\Users\hones\Desktop\MWO data\chromedriver.exe")

login_screen = driver.get("https://mwomercs.com/profile/leaderboards")
username = driver.find_element_by_id("email").send_keys("login_here")
password = driver.find_element_by_id("password").send_keys("some_password")
submit = driver.find_element_by_xpath("//*[@id='loginForm']/form/button").click()

stats = driver.find_elements_by_xpath("//*[@id='contentBody']/div[2]/table/tbody/tr[1]")
print(stats)

Everything works fine and no error message is presented. However, instead of returning the number I am trying to scrape, it returns something entirely different and it is displayed below.

[<selenium.webdriver.remote.webelement.WebElement (session="ebff9ddc3b927111b738557f1767aa58", element="d02991c8-c093-4d57-97e7-53b5bc8f75bd")>]

How would I go about getting past this and getting the data I am after? Thanks in advance for any feedback that is given.
Quote:[<selenium.webdriver.remote.webelement.WebElement (session="ebff9ddc3b927111b738557f1767aa58", element="d02991c8-c093-4d57-97e7-53b5bc8f75bd")>]

This is being return by your print statement,
stats = driver.find_elements_by_xpath("//*[@id='contentBody']/div[2]/table/tbody/tr[1]")
print(stats)
The above method will return all the possible elements which matches with the xpath you mentioned in list form. You can loop through that variable stats and print each element to see