51Testing软件测试论坛
标题:
selenium IDE录制的脚本另存为python脚本后运行失败
[打印本页]
作者:
32712784
时间:
2015-9-3 23:59
标题:
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 [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()
复制代码
作者:
32712784
时间:
2015-9-5 22:49
没人来看一眼么~~
作者:
abbybeach
时间:
2015-9-6 17:08
没看明白报的是什么错
作者:
32712784
时间:
2015-9-10 21:43
已经找到 问题了。。。没切换frame
作者:
tyy_02
时间:
2015-9-12 21:58
IDE录制的代码另存为脚本文件时,有时会丢失一些动作,但是回放是没问题的
作者:
ch4isme
时间:
2015-10-16 17:31
ide语言能实现的方法不一定对应有python下的实现,还是建议ide用于辅助 ,脚本自己写吧
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2