Selenium RC python code snippet

启动浏览器

self.selenium = selenium("localhost", 4444, "*firefox", "http://218.108.8.83:2048")

 

打开根页面

sel.open("/")

 

等待元素出

def waitForElement(self, elementName):

for i in range(60):

try:

if self.selenium.is_element_present(elementName): break

except: pass

time.sleep(1)

else: self.fail("time out")

 

键入数据:

sel.type("//input[@id='ProgramScheduleModel_url']", "http://justNothing.com")

sel.type("//textarea[@id='ProgramScheduleModel_summary']", u"凹凸曼大战小怪兽")

 

选择drop down 列表:

sel.select("//select[@id='ProgramScheduleModel_startHour']", "index=%d" % startHour)

sel.select("//select[@id='ProgramScheduleModel_startMinute']", "index=0")

 

 

点击超链接:

sel.click(u"link=添加播放日程")

 

点击某个form下面的button

sel.click("//form[@id='program-schedule-model-form']//input[@name='yt0']")

 

posted @ 2011-05-25 11:46  hjtc  Views(362)  Comments(0Edit  收藏  举报