2011-03-11 144 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)来测试它。如果那有效,那么它意味着在你的情况下需要有条件的等待。