简体   繁体   English

Python:要在Unittest中运行Selenium,我需要在程序目录中包括哪些模块?

[英]Python: What modules do I need to include in the directory of my program to run Selenium with Unittest?

I am trying to run the following code using the Pycharm IDE: 我正在尝试使用Pycharm IDE运行以下代码:

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.send_keys("selenium")
        elem.send_keys(Keys.RETURN)

    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
    unittest.main()

I get the following error when I do: 我这样做时会收到以下错误:

Traceback (most recent call last):
File "/Users/BigRed/PycharmProjects/python 3/source.py", line 8, in setUp
self.driver = webdriver.Firefox()
AttributeError: 'module' object has no attribute 'Firefox'

In the directory of the source file, I also have the selenium folder, which contains the webdriver files, as well as exceptions.py and selenium.py . 在源文件的目录中,我还有selenium文件夹,其中包含webdriver文件以及exceptions.pyselenium.py Is there something I am missing? 我有什么想念的吗? Or is the problem something different altogether? 还是问题完全不同?

Thanks for your help. 谢谢你的帮助。

I also faced same problem and i did like this 我也遇到同样的问题,我确实是这样

1) open terminal (ctrl+alt+t)
2) check $ python --version
3) now install firefox using pip or sudo apt-get

or 要么

1) open terminal (ctrl+alt+t)
2) check $ python --version                  (2.7.5....) and 
3) In pycharm go to project interpreter and select the same python version as project interpreter.

4) Now run it will work. 4)现在运行即可。

暂无
暂无

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

相关问题 selenium Python 中的单元测试是什么? - What is unittest in selenium Python? Python selenium - 如何运行 Selenium ZA7F5F35426B927411FC9231B536 单元 - Python selenium - How to run a Selenium Python Unittest 从命令行在Linux上运行Python GUI程序需要什么软件包 - What Packages do I need to run a Python GUI program on Linux from the command line 从Anaconda Cloud下载后,我需要将目录放入哪个目录? - What directory do I need to put my python packages in after downloading them from Anaconda Cloud? 我需要添加什么,让我的Python 3程序检查输入是升序还是降序? - What do I need to add, to ask my Python 3 program to check if the input is in ascending or descending order? 我需要通过 python 模块我的程序,我该怎么做 - I need module my program by python,how I do 要在我的浏览器中成功运行一个执行Python脚本的网站,我需要什么? - What do I need to successfully run a website in my browser that executes Python scripts? 在 python 中使用单元测试的正确方法是什么,测试模块位于主 package 内的目录中? - What is the correct way to use unittest in python with the test modules in a directory inside the main package? 我是否总是需要在 Python 中指定我当前的工作目录? - Do I always need to specify my current working directory in Python? 为什么我需要点击两次才能退出我的 python 程序? - Why do I need to click twice to exit my python program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM