我可以打开浏览器,并写邮政编码,但它不点击,它返回“没有邮政编码”的结果为搜索,实际上它有。
import time
import pandas as pd
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
HOMEPAGE = "https://www.goodmanmfg.com/support/find-a-dealer"
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get(HOMEPAGE)
try:
consent = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//\*\[@id='onetrust-accept-btn-handler'\]"))).click()
except:
print("Cookie Consent Elements Not Found")
pass
driver.find_element(By.XPATH, "//*\[@id='miles'\]").click()
time.sleep(1.3)
driver.find_element(By.XPATH, "//*\[@id='miles'\]/option\[5\]").click()
time.sleep(1.3)
# for zipcode in zipcodes:
for zipcode in ['50315', '50314']:
postcode_input_box = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='zipcode']")))
postcode_input_box.clear()
postcode_input_box.send_keys(zipcode + Keys.RETURN)
driver.find_element(By.XPATH, '//button[normalize-space()="SEARCH"]').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='zipFilterWrap']/div[1]/div/div[3]/button"))).click()
1条答案
按热度按时间cu6pst1q1#
存在1个逻辑问题和一些代码问题:
**1.代码问题有:**首先,为什么要使用转义斜杠?在第17行:
它应该是这样的:
类似地,第22和24行:
和第32行,为什么需要RETURN?已经在下一行,您将单击:
**2.逻辑问题:**即使在我修复了代码问题之后,我仍然看到它重定向到facebook,所以在您的应用程序的源代码中可能存在这样的自动化阻塞结构