我正在嘗試在我自己的 chrome 中打開瀏覽器。我正在使用 Selenium WebDriver,但我想使用我自己的 chrome 瀏覽器。
我的代碼:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')
driver.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")
buyButton = False
while buyButton is False:
try:
addToCartBtn = addButton = driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')
print("Varen er udsolgt")
time.sleep(1)
driver.refresh()
except:
addToCartBtn = addButton = driver.find_element_by_xpath('//*[@id="picker-trigger"]')
print("Varen er p? Lager")
buyButton = True
while buyButton is True:
time.sleep(1)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='V?lg st?rrelse']"))).click()
driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='L?g i indk?bskurv']"))).click()
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Indk?bskurv"]'))).click()
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".z-coast-base__totals-tile .z-1-button__content"))).click()
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Registrér dig"]'))).click()
我試過的:
driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')
錯誤:
selenium.common.exceptions.WebDriverException: Message: 'driver' executable needs to be in PATH.
我試圖遵循這個答案,但我無法讓它發揮作用。
uj5u.com熱心網友回復:
試試這個:
import webbrowser
url = 'http://docs.python.org/'
# MacOS
chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
# Windows
# chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
# Linux
# chrome_path = '/usr/bin/google-chrome %s'
webbrowser.get(chrome_path).open(url)
uj5u.com熱心網友回復:
您可以指定 chromedriver 和/或 chrome 的路徑,例如:
chromedriver = '/path/to/chromedriver'
options = Options()
options.binary_location = '/path/to/chrome'
driver = webdriver.Chrome(chromedriver, chrome_options=options)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/414451.html
標籤:
上一篇:WebDriverException:訊息:未知錯誤:無法洗掉舊的devtools埠檔案錯誤,更新函式中的SeleniumOptions()
