[英]Selenium Python/Django: using it with chromedriver on ubuntu
I have the following code in a Django app chat's 我在Django应用聊天中有以下代码
from channels.testing import ChannelsLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
class ChatTests(ChannelsLiveServerTestCase):
serve_static = True # emulate StaticLiveServerTestCase
@classmethod
def setUpClass(cls):
super().setUpClass()
try:
# NOTE: Requires "chromedriver" binary to be installed in $PATH /home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/
cls.driver = webdriver.Chrome(executable_path="/home/muiruri_samuel/webapp/chatsys/chat/chromedriver")
except:
super().tearDownClass()
raise
...
it's supposed to check! 应该检查一下! if channels works ok, but before that fails to connect to the ChromeDriver with this error
如果频道正常,但在此之前无法连接到ChromeDriver,并显示此错误
(chatenv) muiruri_samuel@train:~/webapp/chatsys$ python manage.py test chat.tests
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: setUpClass (chat.tests.ChatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", l
ine 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/muiruri_samuel/webapp/chatsys/chat/chromedriver':
'/home/muiruri_samuel/webapp/chatsys/chat/chromedriver'
line 68, in __init__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/muiruri_samuel/webapp/chatsys/chat/tests.py", line 14, in setUpClass
cls.driver = webdriver.Chrome(executable_path="/home/muiruri_samuel/webapp/chatsys/chat/chromedriver")
File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
----------------------------------------------------------------------
Ran 0 tests in 0.006s
FAILED (errors=1)
Destroying test database for alias 'default'...
It "doesn't" find the driver on the PATH /home/muiruri_samuel/webapp/chatsys/chat/chromedriver
and I've also tried copying it to the sites-packages /home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/
它“没有”在PATH
/home/muiruri_samuel/webapp/chatsys/chat/chromedriver
找到驱动程序,我也尝试将其复制到sites-packages /home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/
According to muiruri_samuel@train:~/webapp/chatsys$ python manage.py test chat.tests
command, you're running the code from folder webapp/chatsys
. 根据
muiruri_samuel@train:~/webapp/chatsys$ python manage.py test chat.tests
命令,您正在从webapp/chatsys
文件夹运行代码。 So it will be a working directory. 因此它将是一个工作目录。 Thus it won't find
chromedriver
in subdirectories, including ./chat
. 因此,它不会找到
chromedriver
子目录中,包括./chat
。 Try moving chromedriver
to /usr/bin
for example. 例如,尝试将
chromedriver
移动到/usr/bin
。 And make sure it's in PATH
variable: echo $PATH
并确保它在
PATH
变量中: echo $PATH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.