2016-07-05 92 views
1

this question給出瞭如何使用Selenium WebDriver使用Java來處理身份驗證彈出窗口的答案。現在,這可以用於python嗎?它看起來像Python驅動程序沒有像Java掛件一樣的UserAndPassword類。如何使用python處理Selenium WebDriver的身份驗證彈出窗口?

這是我曾嘗試:

wait = WebDriverWait(driver, 10) 
    alert = wait.until(ExpectedConditions.alertIsPresent()) 
    alert.authenticateUsing(UserAndPassword("user","passwd")) 

回答

0

事實上在Python硒庫中沒有這樣的類,但你可以伊斯利導航使用其他手段給予警告,並輸入用戶名和密碼。

wait = WebDriverWait(driver, 10) 
alert = wait.until(ExpectedConditions.alert_is_present()) 
alert = driver.switch_to_alert() 
alert.send_keys('username') 
alert.send_keys(Keys.TAB) 
alert.send_keys('password') 
alert.accept() 

這將工作在標準身份驗證,如果它是自定義的,你可能會修補它的abit。

+0

不行不行。我想我提出的身份驗證框不是'提醒',而是其他的東西。所以,警報永遠不會出現。但一盒是。請參閱http://stackoverflow.com/questions/36789858/how-to-fill-fields-in-a-popup-when-opening-a-sharepoint-website-with-selenium-us以查看此框的外觀... – Alex

相關問題