15889369825 发表于 2016-10-11 14:19:49

有selenium IDE录制的脚本导入到

selenium IDE录制的脚本导入到python IDLE中 运行报错
C:\Users\admin\Desktop\2.png
C:\Users\admin\Desktop\2.png

若尘_51 发表于 2016-10-11 17:32:44

15889369825 发表于 2016-10-11 17:29
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import...

你附图的那个脚本为啥少了class
还有函数名不能包含中文的

15889369825 发表于 2016-10-11 14:25:36

小白级别,不知道怎么错了,求解

若尘_51 发表于 2016-10-11 15:29:59

这个报错通常是:行缩进问题(空格或Tab的使用,看看光标停留在哪里),或者就是缺少括号

15889369825 发表于 2016-10-11 16:34:01

若尘_51 发表于 2016-10-11 15:29
这个报错通常是:行缩进问题(空格或Tab的使用,看看光标停留在哪里),或者就是缺少括号

光标就停留在def那里,行缩进是缩进四个字符么

若尘_51 发表于 2016-10-11 17:05:30

15889369825 发表于 2016-10-11 16:34
光标就停留在def那里,行缩进是缩进四个字符么

你的脚本的def函数那里是不需要缩进的:

brower=xxx
def setUp(self):
    xxx
    xxx

15889369825 发表于 2016-10-11 17:17:50

若尘_51 发表于 2016-10-11 17:05
你的脚本的def函数那里是不需要缩进的:

brower=xxx


不缩进也报同样的错误,这个会不会是我python环境没有装好

掉渣饼 发表于 2016-10-11 17:21:16

感觉是你的文件名称有问题,不能以中文名称命名

若尘_51 发表于 2016-10-11 17:24:53

15889369825 发表于 2016-10-11 17:17
不缩进也报同样的错误,这个会不会是我python环境没有装好

你把脚本附上来,我调调看

15889369825 发表于 2016-10-11 17:26:03

掉渣饼 发表于 2016-10-11 17:21
感觉是你的文件名称有问题,不能以中文名称命名

改了名称也一样,弄得没脾气了

15889369825 发表于 2016-10-11 17:29:58

若尘_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()

若尘_51 发表于 2016-10-11 17:31:57

15889369825 发表于 2016-10-11 17:29
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import...

这个脚本你只需要将
class 3 改成 class test 就可以运行

15889369825 发表于 2016-10-11 17:40:09

若尘_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)

15889369825 发表于 2016-10-11 17:42:10

若尘_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)

15889369825 发表于 2016-10-11 17:43:34

若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

大神就是厉害!不过我这边打不开脚本中的地址

15889369825 发表于 2016-10-11 17:44:57

若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

厉害了大神,可我这边又出现新问题,打不开脚本中的地址

15889369825 发表于 2016-10-11 17:47:28

若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

不好意思了!应该是调试修改时把class删除了

15889369825 发表于 2016-10-11 17:50:44

若尘_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)

15889369825 发表于 2016-10-11 17:58:30

应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
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)
这是什么原因

15889369825 发表于 2016-10-11 17:58:44

应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
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
查看完整版本: 有selenium IDE录制的脚本导入到