【问题标题】:Controlling cefpython with selenium webdriver使用 selenium webdriver 控制 cefpython
【发布时间】:2018-03-10 15:24:11
【问题描述】:

我正在尝试用 selenium (chromedriver.exe==2.9) 控制 cefpython (cefpython3==57.0) 铬嵌入式框架

我从一开始就走了这么远,我搜索了网络的每个角落,都没有找到关于这个主题的内容。 如果有人有这方面的知识,在这里分享他们的知识,那就太好了。不仅是我,搜索这个问题的每个人都会发现这很有用。

幸运地找到了这个简单的教程 https://github.com/sokolnikovalexey/cef-pyhton-selenium

在第 2 步中作者告诉将 APPLICATION_PATH 设置为 cef 应用程序(cefclient.exe)的路径

很遗憾,我的文件夹中没有该文件。 我只能找到 subprocess.exe "C:\Users\vaas\AppData\Local\Programs\Python\Python36\Lib\site-packages\cefpython3\subprocess.exe"

但这不会启动 cef,我收到 webdriver 错误 使用 chromedriver.exe (2.9) 时:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed

使用 chromedriver.exe (

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

这里是官方的 cef tut,它展示了如何将 chromedriver 与 cef 一起使用,但本教程仅适用于 java。 https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md

这是我在第一个教程中使用的示例代码。

import time
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):

#    APPLICATION_PATH = '/path/to/your/cef/app.exe'
    APPLICATION_PATH = r'C:\Users\vaas\AppData\Local\Programs\Python\Python36\Lib\site-packages\cefpython3\subprocess.exe'
    TEST_PAGE_PATH = 'http://www.google.com' #here should be path to your testing page

    def setUp(self):
        options = webdriver.ChromeOptions()
        options.binary_location = self.APPLICATION_PATH
        self.driver = webdriver.Chrome(chrome_options=options)
        self.driver.get(self.TEST_PAGE_PATH)

    def test_math_operations(self):
        driver = self.driver
        operand1 = driver.find_element_by_id('operand1')
        operand2 = driver.find_element_by_id('operand2')
        result = driver.find_element_by_id('result')
        calculateButton = driver.find_element_by_id('calculateButton')

        operand1.send_keys('2')
        operand2.send_keys('3')
        calculateButton.click()
        assert result.get_attribute('value') == '5'

    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
    unittest.main()

我也联系了教程的作者。 将在此处更新进度。

谢谢。

【问题讨论】:

    标签: python selenium chromium-embedded cefpython


    【解决方案1】:

    您可以通过下载“示例应用程序”包从 Spotify Automated Builds 获取 cefclient.exe:

    http://opensource.spotify.com/cefbuilds/index.html

    但首先您需要找出要下载的 CEF 版本,您需要下载与 cefpython 匹配的确切版本。您可以通过调用cef.GetVersion()["cef_version"]在cefpython中找到CEF版本。

    如果您使用 cefclient.exe,那么您不是在使用 CEF Python,而是在使用 CEF。如果你想将cefpython与selenium一起使用,那么你可以运行cefpython应用程序并为selenium提供远程调试端口,selenium可以通过该端口控制cefpython应用程序。在 cefpython “使用 WebDriver/ChromeDriver2 的自动化示例”中有问题 #63,在评论 #2 中您可以找到示例代码:

    https://github.com/cztomczak/cefpython/issues/63

    【讨论】:

      【解决方案2】:

      我是 repo "cef-python-selenium" 的所有者。 我现在检查我的解决方案,但它不是实际的。我和你有同样的问题。对不起。

      我认为问题在于二进制文件的不同版本。 这是对我有用的新解决方案。但现在我使用的是 nodejs 而不是 python。这次我也提交和二进制文件。 https://github.com/sokolnikovalexey/cef-nodejs-selenium

      希望,这会有所帮助

      【讨论】:

        猜你喜欢
        • 2015-12-23
        • 1970-01-01
        • 1970-01-01
        • 2020-09-20
        • 2020-08-20
        • 1970-01-01
        • 1970-01-01
        • 2020-08-22
        • 2021-07-12
        相关资源
        最近更新 更多