Selenium无法在Copart网站执行Lot号搜索问题排查及课程推荐
代码问题排查与修复
问题分析
你的代码大概率遇到了这两个问题:
- 元素定位错误:
mobile-input-search是移动端页面的搜索框ID,桌面端加载的网页用的是另一个ID(比如input-search),直接定位移动端元素会触发找不到元素的报错。 - 未等待页面加载:网页渲染需要时间,直接调用
find_element可能在搜索框还没渲染完成时执行,引发NoSuchElementException。
修复后的代码
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 保持浏览器不自动关闭的配置 options = webdriver.ChromeOptions() options.add_experimental_option("detach", True) driver = webdriver.Chrome(options=options) driver.get("https://www.copart.com/") # 显式等待搜索框加载完成,使用桌面端的搜索框ID wait = WebDriverWait(driver, 10) search_box = wait.until(EC.presence_of_element_located((By.ID, "input-search"))) # 激活搜索框并输入Lot号 search_box.click() search_box.send_keys("72486533") search_box.send_keys(Keys.RETURN)
新手Selenium课程推荐
- Selenium官方入门指南:从基础API讲起,覆盖Selenium 4.x核心功能,内容更新及时,适合零基础入门。
- B站免费Selenium 4实战系列:搜索「Selenium 4 入门到实战」即可找到,跟着UP主的案例操作能快速上手。
- 付费系统课程:国内主流编程教育平台的「Web自动化测试(Selenium 4)」课程,从环境搭建到项目实战完整覆盖,适合想系统学习的新手。
内容的提问来源于stack exchange,提问作者idkwhatimdoing
相关产品推荐
相关产品推荐

