I tried to make selenium find an element (1 of the listing below) on this site by xpath :
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)
driver.execute_script('window.scrollBy(0, 2000)')
folder = driver.find_element(By.XPATH,'//*[@id="__next"]/div[1]/main/div/div/div[3]/div/div[1]/div/div[3]/div[3]/div/div[2]/div[15]/button/div/div[2]/div/div/div/div[2]/span[2]/a')
print(folder)
but i get an error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/div1/main/div/div/div[3]/div/div1/div/div[3]/div[3]/div/div[2]/div[15]/button/div/div[2]/div/div/div/div[2]/span[2]/a"}
I know the site made by react, but i didnt manage to get the element. Thanks
CodePudding user response:
why don't use xpath feature?
//div[@role='listitem']//a[contains(@href,'assets')]
right click on node and click on copy xpath is not usefull, you must search in elements with xpath query
folder = driver.find_element(By.XPATH,"//div[@role='listitem']//a[contains(@href,'assets')]")
CodePudding user response:
From PersianMans's answer combined with webdriver waits you can make your program wait for the element to be there. Etc 10 seconds as such.
wait=WebDriverWait(driver, 10)
url="https://opensea.io/collection/mekaverse?tab=activity&search[isSingleCollection]=true&search[eventTypes][0]=AUCTION_CREATED"
driver.get(url)
folder=wait.until(EC.presence_of_element_located((By.XPATH,"//div[@role='listitem']//a[contains(@href,'assets')]")))
print(folder)
Import
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC