有selenium IDE录制的脚本导入到
selenium IDE录制的脚本导入到python IDLE中 运行报错C:\Users\admin\Desktop\2.png
C:\Users\admin\Desktop\2.png 15889369825 发表于 2016-10-11 17:29
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import...
你附图的那个脚本为啥少了class
还有函数名不能包含中文的 小白级别,不知道怎么错了,求解 这个报错通常是:行缩进问题(空格或Tab的使用,看看光标停留在哪里),或者就是缺少括号 若尘_51 发表于 2016-10-11 15:29
这个报错通常是:行缩进问题(空格或Tab的使用,看看光标停留在哪里),或者就是缺少括号
光标就停留在def那里,行缩进是缩进四个字符么 15889369825 发表于 2016-10-11 16:34
光标就停留在def那里,行缩进是缩进四个字符么
你的脚本的def函数那里是不需要缩进的:
brower=xxx
def setUp(self):
xxx
xxx 若尘_51 发表于 2016-10-11 17:05
你的脚本的def函数那里是不需要缩进的:
brower=xxx
不缩进也报同样的错误,这个会不会是我python环境没有装好 感觉是你的文件名称有问题,不能以中文名称命名 15889369825 发表于 2016-10-11 17:17
不缩进也报同样的错误,这个会不会是我python环境没有装好
你把脚本附上来,我调调看 掉渣饼 发表于 2016-10-11 17:21
感觉是你的文件名称有问题,不能以中文名称命名
改了名称也一样,弄得没脾气了 若尘_51 发表于 2016-10-11 17:24
你把脚本附上来,我调调看
# -*- 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 3(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://test.robotscloud.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_3(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("email").clear()
driver.find_element_by_id("email").send_keys("15889369825@163.com")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("123456")
driver.find_element_by_id("check").clear()
driver.find_element_by_id("check").send_keys("5223")
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as 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()
15889369825 发表于 2016-10-11 17:29
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import...
这个脚本你只需要将
class 3 改成 class test 就可以运行 若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的
刚运行了下,打开网页是无效的网址并没有打开我代码中的地址
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\admin\Desktop\3.py", line 12, in setUp
self.driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
self.binary, timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
"The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
----------------------------------------------------------------------
Ran 1 test in 15.122s
FAILED (errors=1) 若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的
附图的自己调试时被删除了,
运行了出现这个报错
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\admin\Desktop\3.py", line 12, in setUp
self.driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
self.binary, timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
"The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
----------------------------------------------------------------------
Ran 1 test in 21.165s
FAILED (errors=1) 若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的
大神就是厉害!不过我这边打不开脚本中的地址 若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的
厉害了大神,可我这边又出现新问题,打不开脚本中的地址 若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的
不好意思了!应该是调试修改时把class删除了 若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的
估计是调试的时候被我删除了,不好意思了
现在运行时打不开我脚本中的地址,后面报
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\admin\Desktop\3.py", line 12, in setUp
self.driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
self.binary, timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
"The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
----------------------------------------------------------------------
Ran 1 test in 21.165s
FAILED (errors=1) 应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\admin\Desktop\3.py", line 12, in setUp
self.driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
self.binary, timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
"The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
----------------------------------------------------------------------
Ran 1 test in 21.165s
FAILED (errors=1)
这是什么原因
应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\admin\Desktop\3.py", line 12, in setUp
self.driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
self.binary, timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
"The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
----------------------------------------------------------------------
Ran 1 test in 21.165s
FAILED (errors=1)
这是什么原因
页:
[1]
2