Selenium Python/Django:在ubuntu上与chromedriver一起使用

2024-04-26 11:16:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Django应用程序聊天中有以下代码

在测试.py在

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

    ...

应该检查一下!如果通道工作正常,但在此之前无法连接到ChromeDriver

^{pr2}$

它“找不到”路径/home/muiruri_samuel/webapp/chatsys/chat/chromedriver上的驱动程序,我也尝试过将其复制到sites包/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/


Tags: fromimporthomelibseleniumchromedriverwebappcls
1条回答
网友
1楼 · 发布于 2024-04-26 11:16:08

根据muiruri_samuel@train:~/webapp/chatsys$ python manage.py test chat.tests命令,您正在运行文件夹webapp/chatsys中的代码。 所以它将是一个工作目录。因此它不会在子目录中找到chromedriver,包括./chat。 例如,尝试将chromedriver移动到/usr/bin。 并确保它在PATH变量中:echo $PATH

相关问题 更多 >