Home > Blockchain >  Python - Selenium (XPath) "Message: no such element: Unable to locate element"
Python - Selenium (XPath) "Message: no such element: Unable to locate element"

Time:11-14

im trying to interact with a website. I want to apply some filters but i have an error, my code does not recognize the xpath.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

options=Options()
options.add_argument('--windoes-size=1920,1080')
driver=webdriver.Chrome(options=options)
driver.get("https://dexscreener.com/polygon/uniswap")

folder=driver.find_element(By.XPATH,'//button[@]')
folder.click()
folder=driver.find_element(By.XPATH,'//button[@id="menu-list-36-menuitem-33"]')
folder.click()

CodePudding user response:

Have you tried using CSS_SELECTOR? I was working with Selenium recently, and sometimes when XPATH was not working, CSS_SELECTOR was.

folder=driver.find_element(By.CSS_SELECTOR, "selector here")

CodePudding user response:

You should use another XPATH for option choosing. Seems like ids for options may be generated dynamically.

So you can try following XPATHs for different filters:

//button[@value="m5"]   # Last 5 minutes button
//button[@value="h1"]   # Last hour
//button[@value="h6"]   # Last 6 hours
//button[@value="h24"]  # Last 24 hours

This way it works fine for me.

  • Related