jett chen
jett chen

Reputation: 1173

python selenium chrome alert no callable?

i write a script to login in router and upgrade fireware, but chrome pop up a alter, and selenium code can't get alert info? can anyone help me?

#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

The result:

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()

Upvotes: 1

Views: 2744

Answers (2)

Murthi
Murthi

Reputation: 5347

Alert object is not callable? Then you should stop calling it. So modify

browser.switch_to.alert().accept()

to

browser.switch_to.alert.accept()

(So remove the () after alert).

Upvotes: 3

Prakash Palnati
Prakash Palnati

Reputation: 3409

driver.switch_to.alert is deprecated.

it is switch_to_alert() not switch_to.alert()

Also consider doing Alert(driver).accept() or Alert(driver).dismiss()if you have only one alert and want to get it out of your way.

Upvotes: 1

Related Questions