4

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?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
CryptoAngel
  • 43
  • 1
  • 4

1 Answers1

7

You are seeing it right.

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)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you, that's great! How do I find part of text in cell if I run it like this '//tbody[1]/tr/td[10]' so it will go all table rows on specific column? Lets say I look only for one word in this in 3 word of the cell – CryptoAngel Dec 03 '21 at 00:54
  • @CryptoAngel Glad to be able to help you. Feel free to raise a new question as per your new requirement. – undetected Selenium Dec 03 '21 at 08:20