使用Python Selenium Webdriver打开Electron应用程序

5

我一直试图通过利用我在Python上使用Selenium Webdriver的经验,绕过使用Spectron进行Electron应用程序的端到端测试。结合Chromedriver入门页面和几个资源的组合,它似乎是可行的,以下是我的解决方案:

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浏览器而不是Electron应用程序。
我看到的大多数资源都是几年前的,因此可能已经发生了某些变化,导致这种方法不再可行。
有没有人知道如何使用Python Selenium WebDriver测试Electron应用程序?

我认为这个链接可以帮到你:https://dev59.com/Ibz4oIgBc1ULPQZFvcL5 - Haythem
1个回答

5

以下内容对我非常有效

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

显然我过于复杂化了。谢谢! - Yoni Shurygin
1
你知道为什么我尝试启动Atom或GitKraken(它们是Electron应用程序)时,它们无法正常工作吗? - user979222

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接