在Ubuntu服务器后台使用Selenium

问题描述

我决定测试我的网站,我在 Windows 10 中编写了 Python Selenium 代码,然后部署在 Ubuntu/Debian 服务器(不是 GUI)中,但它不起作用。

当我使用 python3 main.py 运行代码时,没有任何反应,没有错误或日志,只是静止。

有趣的是,这段代码在 Windows 中工作,例如 GU 作为背景,当我尝试简单的 selenium 代码时,只需打开浏览器并在 Ubuntu Server 中编写一些内容,它就可以工作,但这段代码却没有。

import polling2
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.chrome.options import Options
import selenium as se
from webdriver_manager.chrome import ChromeDriverManager
from helpers import elementAttributes,telegram
from recourses import elementPaths,elementLocators,testMaterials,\
    staticValues
from services import adminConsole



def register_new_user():
    try:
        options = se.webdriver.ChromeOptions()
        options.add_argument('--no-sandBox')
        options.add_argument('headless')
        options.add_argument("--disable-dev-shm-usage")
        driver = webdriver.Chrome(chrome_options=options)
        wait = webdriverwait(driver,10)
        driver.get(staticValues.path_to_get)
        if staticValues.site_name not in driver.title:
            telegram.send_message_to(staticValues.bot_id,staticValues.chat_id,"not found" + staticValues.site_name)

        try:
            print('Registration Try Correctly Working')
            registration_button = driver.find_element_by_xpath(
                elementPaths.button_path)
            registration_button.click()
        except Exception as e:
            telegram.send_message_to(staticValues.bot_id,"not clcik " + str(e))

这是我的代码的一部分。 有什么限制吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)