[英]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.py
和selenium.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.