微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Ubuntu服务器后台使用Selenium

如何解决在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 举报,一经查实,本站将立刻删除。