【发布时间】: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