简体   繁体   English

在运行python的Selenium Webdriver时传递参数

[英]Passing arguments while running selenium webdriver for Python

I am using selenium python webdriver for my python test cases. 我在我的python测试用例中使用了selenium python webdriver。 I have a python script NowSpots_Traffic.py which I'm trying to run from Ubuntu terminal (something similar to command prompt in windows) 我有一个Python脚本NowSpots_Traffic.py,我正尝试从Ubuntu终端运行该脚本(类似于Windows中的命令提示符)

python /home/vijay/Projects/SeleniumScripts/NowSpots_Traffic.py samuel secrete python /home/vijay/Projects/SeleniumScripts/NowSpots_Traffic.py samuel secrete

where samuel and secrete are two arguments which I need to pass to my python script NowSpots_Traffic.py 其中samuel和secrete是我需要传递给python脚本NowSpots_Traffic.py的两个参数

I followed the instructions found at Running Tests in Python with Selenium 2 and WebDriver section "Multiple browsers and multiple platforms". 我按照在使用Selenium 2和WebDriver的Python运行测试中找到的说明进行操作,该说明位于“多个浏览器和多个平台”部分。

But I get the following error message 但是我收到以下错误消息

Traceback (most recent call last):
  File "/home/vijay/Projects/SeleniumScripts/NowSpots_Traffic.py", line 43, in <module>
    unittest.main()
  File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python2.7/unittest/main.py", line 152, in parseArgs
    self.createTests()
  File "/usr/lib/python2.7/unittest/main.py", line 161, in createTests
    self.module)
  File "/usr/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'samuel'

The Unittest.main() function uses the arguments you pass in to determine test cases to run. Unittest.main()函数使用您传入的参数来确定要运行的测试用例。 See here: Test Discovery 参见此处: 测试发现

If your script also needs arguments, you will want to remove them from sys.argv before calling 如果您的脚本也需要参数,则在调用之前,您需要将其从sys.argv中删除。

unittest.main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 权限被拒绝:在 python 中运行 selenium webdriver 时出现“geckodriver.log” - Permission denied: 'geckodriver.log' while running selenium webdriver in python 在 Python 中使用代理运行 Selenium Webdriver - Running Selenium Webdriver with a proxy in Python 通过传递参数在运行Python脚本时出现Process Builder错误 - Process Builder error while running Python script by passing arguments 从jupyter笔记本运行python程序,同时传递文件名作为参数 - Running a python program from jupyter notebook while passing filenames as arguments 使用PhantomJS运行Selenium Webdriver时出现InvalidElementStateException - InvalidElementStateException while running Selenium Webdriver with PhantomJS 通过Selenium和Python通过WebDriver实例调用execute_script()方法时,arguments [0]是什么? - What is arguments[0] while invoking execute_script() method through WebDriver instance through Selenium and Python? 在参数中传递Selenium Webdriver。 Python可能吗? - Passing Selenium Webdriver in a parameter. Is it possible in Python? 将参数传递给正在运行的 python 脚本 - Passing arguments to a running python script 在 Python 中使用代理运行 Selenium Webdriver 不会更改 IP - Running Selenium Webdriver with a proxy in Python not changing IP 从 Python 控制台运行 Selenium webdriver - running Selenium webdriver from Python console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM