python selenium chrome 警报不可调用?

标签 python selenium

我写了一个脚本来登录路由器并升级固件,但是chrome弹出一个alter,selenium代码无法获取警报信息?谁能帮帮我?

#coding:utf-8
import sys
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
reload(sys)
sys.setdefaultencoding('utf-8')

driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get('http://192.168.1.1')

.
.
.

status_frame = driver.find_element_by_xpath('//frame[@src="/admin/status.asp"]')

driver.switch_to.frame(status_frame)
file_upload = driver.find_element_by_name('binary')
submit = driver.find_element_by_name('send')

file_upload.send_keys('E:\upgrate_fw\firmware\ISCOMHT803-DR_T_RC01_SYSTEM_3.0.15(a)_20170103')
submit.click()


alert = driver.switch_to.alert()
time.sleep(3)
print alert.text

结果:

C:\Python27\python.exe E:/router/ISCOM-HT803.py Traceback (most recent call last): File "E:/router/ISCOM-HT803.py", line 43, in alert = driver.switch_to.alert() TypeError: 'Alert' object is not callable

Process finished with exit code 1

show alert dialog after submit.click()

最佳答案

Alert 对象不可调用?那么你应该停止调用它。所以修改

browser.switch_to.alert().accept()

browser.switch_to.alert.accept()

(因此删除 alert 后的 ())。

关于python selenium chrome 警报不可调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45730877/

相关文章:

python - OS X Python : alias not working anymore, 链接到哪里?

automation - 我可以使用 Selenium 访问 DOM 对象吗?

testing - 使用具有随机值的 Selenium IDE

python - 循环浏览页面以进行网页抓取

css - 为什么这个 xpath 可以工作,但 UL 的 css 选择没有 [locator not found]

python - 如何在Odoo环境中写入数据库所有缓存?

python - 如何使 facebook 应用程序允许来自在本地服务器上运行的 django 项目的请求?

python - 为 Python 3.3 安装分发版

Python Lambda 检查 URL 健康状况

python - 无法使用 selenium 和 python 从 html 表中检索链接