2

I am trying to gather recent NFT transaction activity from an OpenSea profile. I am getting an error that states the program is unable to locate the element, however my element has been defined and I copy and pasted the element from the web page.

What I am trying to do is selecting the class that holds all of the activities on the section, and then using XPath to gather each items info and print the item info. After looking at guides, videos, and other peoples code, I am pretty lost on what I am doing wrong.

Any advice would be greatly appreciated.

Here is my code:

from selenium import webdriver
from selenium.webdriver.common.by import By


PATH = ('/Users/chris/Desktop/chromedriver')
driver = webdriver.Chrome(PATH)

driver.get("https://opensea.io/GaryVee?tab=activity")


action = driver.find_element(By.CLASS_NAME, 'Blockreact__Block-sc-1xf18x6-0 dBFmez')

for action in actions:

    nft_name = action.find_element(By.XPATH, './/*[@id="main"]/div/div/div[3]/div/div[3]/div[2]/div/div[2]/div['
                                             '1]/button/div/div[2]/div/div/div/div[2]/span[1]/div/div/a').text

    nft_id = action.find_element(By.XPATH, './/*[@id="main"]/div/div/div[3]/div/div[3]/div[2]/div/div[2]/div['
                                           '1]/button/div/div[2]/div/div/div/div[2]/span[2]/a/div').text

    price_eth = action.find_element(By.XPATH, './/*[@id="main"]/div/div/div[3]/div/div[3]/div[2]/div/div[2]/div['
                                              '1]/button/div/div[3]/div/div[1]/div/div[2]/text()').text

    price_usd = action.find_element(By.XPATH, './/*[@id="main"]/div/div/div[3]/div/div[3]/div[2]/div/div[2]/div['
                                              '1]/button/div/div[3]/div/div[2]/span/div/div').text

    sending_user = action.find_element(By.XPATH, './/*[@id="main"]/div/div/div[3]/div/div[3]/div[2]/div/div[2]/div['
                                                 '1]/button/div/div[5]/div/a/span').text

    recieving_user = action.find_element(By.XPATH, './/*[@id="main"]/div/div/div[3]/div/div[3]/div[2]/div/div['
                                                   '2]/div[1]/button/div/div[6]/div/a/span').text

    status = action.find_element(By.XPATH, './/*[@id="main"]/div/div/div[3]/div/div[3]/div[2]/div/div[2]/div['
                                           '1]/button/div/div[1]/h6').text

    print(nft_name, nft_id, price_eth, price_usd, sending_user, recieving_user, status) 

Here is my error code:

/Users/chris/PycharmProjects/pythonProject/main.py:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(PATH)
Traceback (most recent call last):
  File "/Users/chris/PycharmProjects/pythonProject/main.py", line 11, in <module>
    action = driver.find_element(By.CLASS_NAME, 'Blockreact__Block-sc-1xf18x6-0 dBFmez')
  File "/Users/chris/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 1244, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "/Users/chris/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/Users/chris/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".Blockreact__Block-sc-1xf18x6-0 dBFmez"}
  (Session info: chrome=127.0.0.1)
Stacktrace:
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268

1 Answers1

1

To identify the element you can use either of the following Locator Strategies:

  • Using css_selector:

    options = Options()
    options.add_argument("start-maximized")
    s = Service('C:\\BrowserDrivers\\chromedriver.exe')
    driver = webdriver.Chrome(service=s, options=options)
    driver.get("https://opensea.io/GaryVee?tab=activity")
    action = driver.find_element(By.CSS_SELECTOR, ".Blockreact__Block-sc-1xf18x6-0.Flexreact__Flex-sc-1twd32i-0.FlexColumnreact__FlexColumn-sc-1wwz3hp-0.OpenSeaPagereact__DivContainer-sc-65pnmt-0.dBFmez.jYqxGr.ksFzlZ.iRiGb")
    
  • Using xpath:

    options = Options()
    options.add_argument("start-maximized")
    s = Service('C:\\BrowserDrivers\\chromedriver.exe')
    driver = webdriver.Chrome(service=s, options=options)
    driver.get("https://opensea.io/GaryVee?tab=activity")     
    action = driver.find_element(By.XPATH, "//*[@class='Blockreact__Block-sc-1xf18x6-0 Flexreact__Flex-sc-1twd32i-0 FlexColumnreact__FlexColumn-sc-1wwz3hp-0 OpenSeaPagereact__DivContainer-sc-65pnmt-0 dBFmez jYqxGr ksFzlZ iRiGb']")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352