首页 文章

使用Python Selenium Webdriver打开Electron Application

提问于
浏览
4

我一直试图通过利用我在Python上使用Selenium Webdriver的经验来绕过使用Spectron for End2End测试电子应用程序 . 使用Chromedriver入门页面的组合,以及几个似乎暗示可行的resources,这就是我提出的:

from selenium import webdriver
import selenium.webdriver.chrome.service as service
servicer = service.Service('C:\\browserDrivers\\chromedriver_win32\\chromedriver.exe')
servicer.start()
capabilities = {'chrome.binary': 'C:\\path\\to\\electron.exe'}
remote = webdriver.remote.webdriver.WebDriver(command_executor=servicer.service_url, desired_capabilities = capabilities, browser_profile=None, proxy=None, keep_alive=False

问题是,它不是打开电子应用程序,而是打开Chrome的标准实例 .

我见过的大部分资源都已经存在了好几年了,所以有些东西可能已经改变,使其不再可能 .

有谁知道使用Python Selenium WebDriver测试Electron应用程序的方法?

1 回答

  • 4

    以下对我来说很有用

    from selenium import webdriver
    
    
    options = webdriver.ChromeOptions()
    options.binary_location = "/Applications/Electron.app/Contents/MacOS/Electron"
    
    driver = webdriver.Chrome(chrome_options=options)
    
    driver.get("http://www.google.com")
    
    
    driver.quit()
    

相关问题