Python Forum
Selenium returning web element instead of desired text - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Selenium returning web element instead of desired text (/thread-23095.html)



Selenium returning web element instead of desired text - newbie_programmer - Dec-11-2019

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.


RE: Selenium returning web element instead of desired text - Malt - Dec-11-2019

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