2011-03-11 49 views
3

我正在運行一個selenium服務器(v.2.0b2)並編寫一個python腳本來運行我的webapp上的測試套件。使用Selenium-rc獲取確認窗口

from selenium import webdriver 
import selenium 

selenium = selenium.selenium('127.0.0.1', 3333, '*firefox', 'http://localhost/') 
selenium.start() 
profile = webdriver.FirefoxProfile('selenium') 
browser = webdriver.Firefox(profile) 
browser.get('http://localhost:8080/index.html?no_auto_login=1') 

我有一個登錄按鈕彈出一個確認對話框,但它需要一個往返的服務器和回它彈出之前。

submit_button = browser.find_element_by_css_selector('#btnSubmit') 
submit_button.click() 
alert = browser.switch_to_alert() 
assert alert.text == 'Server Login Error...' 
alert.accept() 

註釋掉submit_button.click之後的項目(),然後調用 selenium.is_confirmation_present() 返回false

我怎麼能等待確認框可見?爲什麼不selenium.is_confirmation_present()返回true?

回答

0

我沒有使用過Selenium 2.0(網絡驅動程序),但會建議你使用Thread.sleep(10)來測試它。如果那有效,那麼它意味着在你的情況下需要有條件的等待。