【问题标题】:how to click Ok on pop up in python selenium如何在 python selenium 弹出窗口中单击确定
【发布时间】:2021-03-05 14:45:17
【问题描述】:

单击保存按钮后,我需要在弹出窗口中单击“确定”

我试过了

警报 = driver.switch_to_alert alert.accept()

但它不工作我得到一个错误 AttributeError: 'function' object has no attribute 'accept'

【问题讨论】:

  • 右键单击并检查元素以检查它是什么 html 元素。
  • 你的意思是检查弹出窗口?没有html元素

标签: python selenium


【解决方案1】:

试试这个:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

ok_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[contains(text(), "OK")]'))).click()

【讨论】:

  • 第 82 行,在 中 ok_button = WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.XPATH, '//button[contains(text(), "OK") ]'))).click()
  • 复制你的 xpath 并粘贴它而不是 '//button[contains(text(), "OK")]'
  • 我实际上无法检测到确定按钮的元素
猜你喜欢
  • 1970-01-01
  • 2020-11-06
  • 2021-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多