-1
from bs4 import BeautifulSoup
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


url = "https://www.deadstock.de/releases/"

PATH = "C:\Program Files (x86)\chromedriver.exe"
chrome_options = Options()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(PATH, options = chrome_options)

driver.get(url)
content = driver.page_source.encode('utf-8').strip()
soup = BeautifulSoup(content,"html.parser")


elements = driver.find_element_by_xpath("""//a[@class='_brlbs-btn _brlbs-btn-accept-all _brlbs-cursor']""")
elements.click()

elements = driver.find_elements_by_xpath("""//div[@class='release-cols']""")
elements[4].click()

time.sleep(2)
elements = driver.find_element_by_xpath("""/html/body/div[3]/main/article/div/div[2]/aside/section[2]/ul/li[1]/div/a""")
elements.click()

time.sleep(5)
# elements = driver.find_element_by_link_text("Verkaufen")
# elements = driver.find_element_by_class_name('chakra-link css-85ri46')
# elements = driver.find_element_by_xpath("""//div[class='chakra-stack css-12vwdz3']""")
elements = driver.find_element_by_id("chakra-button css-14gn5pw")
elements.click()

Hey I am trying to scraep prices off of stockx from upcoming sneakers. First the porgramm finds the sneaker and then presses on the stockx link. From Stockx i would like to press on the red "SELL" button. I have tried so many different ways but I cannot seem to find a way to locate or press the link. Any help much appreciated!!!

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

Once you click on Stockx Zum Shop the link opens in a new TAB so you need to shift Selenium's focus to the new TAB and then click() on the Verkaufen link as follows:

driver.get("https://www.deadstock.de/releases/")
windows_before  = driver.current_window_handle
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='cookie-box']//a[@class='_brlbs-btn _brlbs-btn-accept-all _brlbs-cursor']"))).click()
elements = driver.find_elements_by_xpath("""//div[@class='release-cols']""")
elements[4].click()
time.sleep(2)
elements = driver.find_element_by_xpath("""/html/body/div[3]/main/article/div/div[2]/aside/section[2]/ul/li[1]/div/a""")
elements.click()
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))
windows_after = driver.window_handles
new_window = [x for x in windows_after if x != windows_before][0]
driver.switch_to.window(new_window)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@aria-label='Close']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Verkaufen"))).click()

You have to add the following imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352