Python Selenium按钮.click()导致浏览器控制台错误



我正试图点击https://www.autozone.com

from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
URL = "https://www.autozone.com/"

caps = DesiredCapabilities().CHROME
caps["pageLoadStrategy"] = "eager"
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
waitDriver = WebDriverWait(driver, 10)
driver.get(URL)
add_vehicle_button = waitDriver.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-testid='deskTopVehicle-menu-lg']")))
add_vehicle_button.click()
waitDriver.until(EC.element_to_be_clickable((By.ID, "yearheader"))).click()
year_button = waitDriver.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-testid='yearheader-dropdown-list-item-1']")))
year_button.click()
waitDriver.until(EC.element_to_be_clickable((By.ID, "makeheader"))).click()
make_button = waitDriver.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-testid='makeheader-dropdown-list-item-1']")))
make_button.click()

在year_button.click((之后运行程序时,会引发浏览器错误,弹出窗口消失

framework-92798cb7dae0e0c5.js:10 TypeError: Cannot read properties of null (reading 'title')
at ag (1479-2923fb31debee947.js:1:20112)
at fs (framework-92798cb7dae0e0c5.js:10:59098)
at f1 (framework-92798cb7dae0e0c5.js:10:68616)
at i (framework-92798cb7dae0e0c5.js:10:112207)
at hr (framework-92798cb7dae0e0c5.js:10:98463)
at hp (framework-92798cb7dae0e0c5.js:10:98391)
at ho (framework-92798cb7dae0e0c5.js:10:98254)
at hg (framework-92798cb7dae0e0c5.js:10:95233)
at framework-92798cb7dae0e0c5.js:10:45040
at b.unstable_runWithPriority (framework-92798cb7dae0e0c5.js:24:9736)
gi @ framework-92798cb7dae0e0c5.js:10
f.componentDidCatch.c.callback @ framework-92798cb7dae0e0c5.js:10
eK @ framework-92798cb7dae0e0c5.js:10
gp @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
aM @ framework-92798cb7dae0e0c5.js:10
bR @ framework-92798cb7dae0e0c5.js:10
main-3fe83d5d1863abe4.js:1          GET https://www.autozone.com/images/icon-store-selected-t.svg 403
(anonymous) @ main-3fe83d5d1863abe4.js:1
f @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
updateHead @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
hz @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
hw @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
aM @ framework-92798cb7dae0e0c5.js:10
bR @ framework-92798cb7dae0e0c5.js:10
icon-oops.svg:1          GET https://www.autozone.com/images/icon-oops.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gf @ framework-92798cb7dae0e0c5.js:10
hs @ framework-92798cb7dae0e0c5.js:10
hr @ framework-92798cb7dae0e0c5.js:10
hp @ framework-92798cb7dae0e0c5.js:10
ho @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
aM @ framework-92798cb7dae0e0c5.js:10
bR @ framework-92798cb7dae0e0c5.js:10
az_locator.svg:1          GET https://www.autozone.com/cdn/icons/az_icons/az_locator.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gy @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
hb @ framework-92798cb7dae0e0c5.js:10
fQ @ framework-92798cb7dae0e0c5.js:10
m.tagName.j.current.g.root @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
az-box.svg:1          GET https://www.autozone.com/images/footer/az-box.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gy @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
hb @ framework-92798cb7dae0e0c5.js:10
fQ @ framework-92798cb7dae0e0c5.js:10
m.tagName.j.current.g.root @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
az-compose.svg:1          GET https://www.autozone.com/images/footer/az-compose.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gy @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
hb @ framework-92798cb7dae0e0c5.js:10
fQ @ framework-92798cb7dae0e0c5.js:10
m.tagName.j.current.g.root @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
new-facebook.svg:1          GET https://www.autozone.com/images/socialmedia/new-facebook.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gy @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
hb @ framework-92798cb7dae0e0c5.js:10
fQ @ framework-92798cb7dae0e0c5.js:10
m.tagName.j.current.g.root @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
new-twitter.svg:1          GET https://www.autozone.com/images/socialmedia/new-twitter.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gy @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
hb @ framework-92798cb7dae0e0c5.js:10
fQ @ framework-92798cb7dae0e0c5.js:10
m.tagName.j.current.g.root @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
new-you-tube.svg:1          GET https://www.autozone.com/images/socialmedia/new-you-tube.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gy @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
hb @ framework-92798cb7dae0e0c5.js:10
fQ @ framework-92798cb7dae0e0c5.js:10
m.tagName.j.current.g.root @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
new-Instagram.svg:1          GET https://www.autozone.com/images/socialmedia/new-Instagram.svg 403
Image (async)
A @ framework-92798cb7dae0e0c5.js:10
gy @ framework-92798cb7dae0e0c5.js:10
hu @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
ht @ framework-92798cb7dae0e0c5.js:10
hg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
eo @ framework-92798cb7dae0e0c5.js:10
er @ framework-92798cb7dae0e0c5.js:10
eq @ framework-92798cb7dae0e0c5.js:10
hb @ framework-92798cb7dae0e0c5.js:10
fQ @ framework-92798cb7dae0e0c5.js:10
m.tagName.j.current.g.root @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
(anonymous) @ _app-1cb58c4ab13ffd1d.js:47
main-3fe83d5d1863abe4.js:1          GET https://www.autozone.com/_next/static/chunks/6408-1bd3c80aa85d4b2d.js net::ERR_ABORTED 403
document.querySelector.c.set.e @ main-3fe83d5d1863abe4.js:1
k @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
(anonymous) @ main-3fe83d5d1863abe4.js:1
f @ main-3fe83d5d1863abe4.js:1
loadRoute @ main-3fe83d5d1863abe4.js:1
loadPage @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
prefetch @ main-3fe83d5d1863abe4.js:1
c.<computed> @ main-3fe83d5d1863abe4.js:1
p @ _app-1cb58c4ab13ffd1d.js:47
onMouseEnter @ _app-1cb58c4ab13ffd1d.js:47
aW @ framework-92798cb7dae0e0c5.js:10
a0 @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
df @ framework-92798cb7dae0e0c5.js:10
dg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
aO @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
dm @ framework-92798cb7dae0e0c5.js:10
bU @ framework-92798cb7dae0e0c5.js:10
bT @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
bS @ framework-92798cb7dae0e0c5.js:10
main-3fe83d5d1863abe4.js:1          GET https://www.autozone.com/_next/static/chunks/pages/trackOrder-659e75ad60d846ea.js net::ERR_ABORTED 403
document.querySelector.c.set.e @ main-3fe83d5d1863abe4.js:1
k @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
(anonymous) @ main-3fe83d5d1863abe4.js:1
f @ main-3fe83d5d1863abe4.js:1
loadRoute @ main-3fe83d5d1863abe4.js:1
loadPage @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
Promise.then (async)
c @ main-3fe83d5d1863abe4.js:1
h @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
(anonymous) @ main-3fe83d5d1863abe4.js:1
prefetch @ main-3fe83d5d1863abe4.js:1
c.<computed> @ main-3fe83d5d1863abe4.js:1
p @ _app-1cb58c4ab13ffd1d.js:47
onMouseEnter @ _app-1cb58c4ab13ffd1d.js:47
aW @ framework-92798cb7dae0e0c5.js:10
a0 @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
df @ framework-92798cb7dae0e0c5.js:10
dg @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
aO @ framework-92798cb7dae0e0c5.js:10
(anonymous) @ framework-92798cb7dae0e0c5.js:10
dm @ framework-92798cb7dae0e0c5.js:10
bU @ framework-92798cb7dae0e0c5.js:10
bT @ framework-92798cb7dae0e0c5.js:10
b.unstable_runWithPriority @ framework-92798cb7dae0e0c5.js:24
bS @ framework-92798cb7dae0e0c5.js:10
ruxitagentjs_A27Vfghjqrux_10249220905100923.js:195          GET https://www.autozone.com/_next/static/css/d7f6188d9650e1ef.css 403

当我在浏览器中手动点击表单时,不会发生这种情况
我不知道为什么Web驱动程序会引发错误,但手动单击时不会。我如何找到根本问题并加以解决?

更新10/2/2022

我在firefox中尝试了相同的代码,并用chrome和firefox用javaselenium库重新编译了代码。同样的错误,";T.error为空";

如果我在顶部添加以下行,不知怎么的,它对我来说是有效的:

options = webdriver.ChromeOptions()
options.add_argument('--disable-blink-features=AutomationControlled')

此外,您需要调整实例化驱动程序的行:

driver = webdriver.Chrome(options=options, service=Service(ChromeDriverManager().install()))

相关内容

  • 没有找到相关文章

最新更新