Home > OS >  Python Selenium: Printing results as [<selenium.webdriver.remote.webelement.WebElement (session=&
Python Selenium: Printing results as [<selenium.webdriver.remote.webelement.WebElement (session=&

Time:12-03

I have this line:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from chromedriver_py import binary_path
import config
import pandas as pd
from pretty_html_table import build_table
from mailjet_rest import Client
from apscheduler.schedulers.blocking import BlockingScheduler

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=binary_path, options=chrome_options)
driver.get('https://coinmarketcap.com/new/')

added_ago = driver.find_elements(By.XPATH, '//tbody[1]/tr[1]/td[10]')
print(added_ago)

Which worked great but I don't understand what changed and now I get strange result like this:

[<selenium.webdriver.remote.webelement.WebElement (session="9dc768d9ede71927c1403c99c6a8005b", element="cdb6a60e-d3dc-4f0a-9f6f-afc12b548552")>]

Any idea?

CodePudding user response:

You are seeing it right.

driver.find_elements() returns a list of elements. You are printing the element itself, so you are seeing, possibly the only element of the list as:

[<selenium.webdriver.remote.webelement.WebElement (session="9dc768d9ede71927c1403c99c6a8005b", element="cdb6a60e-d3dc-4f0a-9f6f-afc12b548552")>]

Ideally, you would like to see an attribute of the WebElements in the list, e.g. innerText and in that case your effective code block will be:

for element in driver.find_elements(By.XPATH, '//tbody[1]/tr[1]/td[10]'):
    print(element.text)
  • Related