简体   繁体   中英

Controlling cefpython with selenium webdriver

I am trying to control cefpython (cefpython3==57.0) chromium embedded framework with selenium (chromedriver.exe==2.9)

I have came so far from beginning, i searched every corner of the web to find none on this topic. It would be great if anyone have knowledge on this share their knowledge here. Not only me, everyone searching this question will find this useful.

Luckily found this simple tutorial https://github.com/sokolnikovalexey/cef-pyhton-selenium

In step 2 author telling to set APPLICATION_PATH to path of cef application(cefclient.exe)

Unfortunately i doun't have that file in my folder. All i can find is subprocess.exe "C:\\Users\\vaas\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\cefpython3\\subprocess.exe"

But this doesn't start the cef, i am getting webdriver error when using chromedriver.exe (2.9):

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

when using chromedriver.exe (<2.9):

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

here is offcial cef tut which show how to use chromedriver with cef, but this tutorial only applicable to java. https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md

here is the sample code i use from the first tutorial.

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()

I have contacted the author of the tutorial as well. Will update the progress here.

Thanks.

You can obtain cefclient.exe from Spotify Automated Builds by downloading "Sample application" package:

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

But first you need to find out which version of CEF to download, you will need to download an exact version that matches cefpython. You can find out CEF version in cefpython by calling cef.GetVersion()["cef_version"] .

If you use cefclient.exe then you're not using CEF Python, but instead you're using CEF. If you want to use cefpython with selenium then you can run cefpython application and provide selenium with remote debugging port with which selenium can control cefpython app. There is Issue #63 in cefpython "Example of automation using WebDriver/ChromeDriver2" and in comment #2 you can find example code:

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

I'm the owner of repo "cef-python-selenium". I check my solution now and it is not actual. I have the same problem as you. Sorry.

I think the problem is in deiiferent versions of binaries. Here is new solution thats works for me. But now I am using nodejs instead of python. This time I commit and binaries too. https://github.com/sokolnikovalexey/cef-nodejs-selenium

Hope, this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM