You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python Selenium禁用Uber Eats地址弹窗失败求助

解决Uber Eats地址弹窗无法通过浏览器参数禁用的问题

你用的--disable-notifications和--disable-popup-blocking仅对浏览器原生通知、系统级弹窗生效,而Uber Eats的「添加地址以查看配送范围」弹窗是页面自身的模态组件,属于网页内容范畴,所以这两个参数对它无效。

直接处理该弹窗的方案如下:

核心思路

放弃浏览器参数禁用的思路,改用Selenium的显式等待定位弹窗元素,直接操作关闭按钮(或输入地址跳过弹窗),同时优先处理可能存在的Cookie同意弹窗,避免干扰后续操作。

完整示例代码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
# 保留参数不影响其他场景,但对目标弹窗无效
options.add_argument("--disable-notifications")
options.add_argument("--disable-popup-blocking")

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
website = "https://www.ubereats.com/gb/store/ammas-kitchen/6AchIeiCS16x5hOVfAhbTQ"
driver.get(website)
driver.maximize_window()

try:
    # 处理Cookie同意弹窗(根据页面实际文案调整定位)
    cookie_btn = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Accept')]"))
    )
    cookie_btn.click()
except Exception as e:
    print("未检测到Cookie弹窗:", e)

try:
    # 等待地址弹窗加载并点击关闭按钮(用浏览器F12查看实际元素属性调整XPATH)
    close_btn = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//button[@aria-label='Close']"))
    )
    close_btn.click()
    print("地址弹窗已关闭")
except Exception as e:
    print("未找到弹窗关闭按钮:", e)

# 后续业务操作...

driver.quit()

注意事项

  • 元素定位需适配页面实际结构:打开浏览器开发者工具(F12),查看弹窗关闭按钮的aria-label、class或文本内容,替换代码中的XPATH。
  • 若弹窗无关闭按钮,可改为定位地址输入框,填入测试地址后点击确认按钮跳过弹窗。

内容的提问来源于stack exchange,提问作者usmanhanif11

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 00:20:45