首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用selenium webdriver控制cefpython

使用selenium webdriver控制cefpython
EN

Stack Overflow用户
提问于 2018-03-10 23:24:12
回答 2查看 1.3K关注 0票数 1

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

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

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

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

不幸的是,我的文件夹里没有那个文件。我能找到的只有"C:\Users\vaas\AppData\Local\Programs\Python\Python36\Lib\site-packages\cefpython3\subprocess.exe“subprocess.exe

但是这并没有启动cef,当我使用chromedriver.exe (2.9)时,我得到了webdriver错误:

代码语言:javascript
复制
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed

使用chromedriver.exe (<2.9)时:

代码语言:javascript
复制
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

下面是官方cef教程,它展示了如何在cef中使用chromedriver,但本教程仅适用于java。https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md

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

代码语言:javascript
复制
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()

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

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2018-03-11 00:42:20

您可以通过下载“示例应用程序”包从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 "Example of automation using WebDriver/ChromeDriver2“中有一个问题#63,在注释#2中你可以找到示例代码:

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

票数 0
EN

Stack Overflow用户

发布于 2018-03-11 17:51:55

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

我认为问题出在二进制文件的不同版本中。这是一个新的解决方案,它对我很有效。但现在我使用nodejs而不是python。这一次我还提交了和二进制文件。https://github.com/sokolnikovalexey/cef-nodejs-selenium

希望,这很有帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49210727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档