|
我用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 [ERROR: Unsupported command [selectFrame | main_frame | ]]
- driver.find_element_by_css_selector("td.tc > input[type=\"checkbox\"]").click() #报错的地方
- driver.find_element_by_link_text(u"上传文件").click()
- # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | null | ]]
- 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()
复制代码
|
|