2017-08-17 48 views
0

我寫了一個腳本在路由器上登錄並升級了fireware,但是chrome彈出了一個修改,並且selenium代碼無法獲得警報信息?誰能幫我?python硒鉻警報不可調用?

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

+0

後submit.click()來完成,那麼將運行這個js

回答

0
driver.switch_to.alert is deprecated. 

switch_to_alert()沒有switch_to.alert()

也可以考慮做Alert(driver).accept()Alert(driver).dismiss(),如果你只有一個警報和W螞蟻讓它脫離你的方式。

0

警報對象不可調用?那麼你應該停止調用它。因此,修改

browser.switch_to.alert().accept() 

browser.switch_to.alert.accept() 

(所以刪除()後警報)。

+0

是的,警報是屬性,而不是方法。我用你的小費來嘗試它,它運行良好。謝謝 –