Selenium RC / Python / JavaScript .aspx /循环语句

Selenium RC / Python / JavaScript .aspx / Loop Statement

本文关键字:循环 语句 aspx Python RC Selenium JavaScript      更新时间:2023-09-26

在过去的几个月里我一直在自学Python。我的第一个项目是使用Selenium RC web驱动框架的浏览器驱动测试用例(虽然没有在我的项目中导入webdriver,以免混淆)。基本上,我的测试用例需要钩入a '的刷新循环。使用JavaScript和HTML编写的aspx'页面。这个循环不断刷新这个.aspx页,直到满足sel.is_text_present("foo")条件。刷新后,直到定义的"文本"出现,脚本应该是click一个JavaScript按钮,与is_text_present字符串一起出现。在执行脚本时,Firefox打开并引导自己到特定的页面并输入其refresh loop,但是当文本出现时(即.aspx页面改变其状态并加载带有JavaScript按钮的JavaScript表),脚本不执行循环的另一个分支。下面的代码片段显示了我实现的逻辑:

i = sel.is_text_present("Schedule")    #text that the test case is 'waiting' for
while i != True:
    print i
    print "Waiting for job..."
    sel.refresh()
else:                
    print "Job found..."
    sel.click("id=Select")
    sel.wait_for_page_to_load("30000")
    sel.click("id=1")
    sel.wait_for_page_to_load("30000")
    print "Success!"
    test_py_s_f_t_c()    #calls this function again to repeat the test case

我的循环语句的逻辑指示Firefox刷新,直到它检测到一个字符串的文本,然后在检测到这个字符串点击一个按钮?是否有可能在按钮id通配符如果按钮的名称是动态的和变化?

纯粹从逻辑上看,这是不正确的。刷新后没有检查文本是否存在

你可以这样写。

i = sel.is_text_present("Schedule")    #text that the test case is 'waiting' for 
while i != True:
    print i
    print "Waiting for job..."
    sel.refresh()
    i = sel.is_text_present("Schedule")    #text that the test case is 'waiting' for
print "Job found..."

我只通过c# API使用了selenium,但是您可以尝试在单击函数

中使用xpath。

sel.click("//输入(包含(@ id, partialId)] ");或者按钮取决于你使用的HTML类型