selenium IDE录制的脚本另存为python脚本后运行失败
我用selenium IDE录制的脚本,回放是正常的,但是我另存为python脚本后,就会报错,想问下为什么会这样呢?下面代码是IDE另存的脚本代码,图片红框是python脚本报错的地方,还请高手能解答一下!
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class IDERecode119(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.119g.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_i_d_e_recode119(self):
driver = self.driver
driver.get(self.base_url + "/Default.aspx#wellcome.aspx")
driver.find_element_by_id("txtUserName").clear()
driver.find_element_by_id("txtUserName").send_keys("xxxxxxxx")
driver.find_element_by_id("txtPwd").clear()
driver.find_element_by_id("txtPwd").send_keys("xxxxxxx")
driver.find_element_by_id("Image1").click()
for i in range(60):
try:
if self.is_element_present(By.CSS_SELECTOR, "a.focus > span"): break
except: pass
time.sleep(1)
else: self.fail("time out")
driver.find_element_by_css_selector("a.focus > span").click()
# ERROR: Caught exception ]
driver.find_element_by_css_selector("td.tc > input").click() #报错的地方
driver.find_element_by_link_text(u"上传文件").click()
# ERROR: Caught exception ]
driver.find_element_by_id("SWFUpload_0").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
{:4_95:}没人来看一眼么~~ 没看明白报的是什么错 :o已经找到 问题了。。。没切换frame IDE录制的代码另存为脚本文件时,有时会丢失一些动作,但是回放是没问题的 ide语言能实现的方法不一定对应有python下的实现,还是建议ide用于辅助 ,脚本自己写吧
页:
[1]