I got a new task to automation an electron app on Mac. So I use python and selenium to start the task.
with the flowing code, I'm able to start the app but after the app is launched, the automation script hangs and not able to even print some messages.
Here is my code right now:
from time import sleep
from selenium import webdriver
def startdriver():
print("start service")
service = webdriver.chrome.service.Service("chromedriver")
service.start()
print("started")
print(service.service_url)
caps = {
'browserName': 'chrome',
'goog:chromeOptions': {
'args': ['--no-sandbox',
'--disable-dev-shm-usage'],
'binary': r"/Applications/Enterprise.app/Contents/MacOS/Enterprise",
'extensions': [],
'windowTypes': ['webview']},
'platform': 'ANY',
'version': ''}
print(caps)
driver = webdriver.remote.webdriver.WebDriver(
command_executor=service.service_url,
desired_capabilities=caps,
#desired_capabilities={'chromeOptions': caps},
browser_profile=None,
proxy=None,
keep_alive=False)
sleep(4)
print("start")
driver.get("http://www.google.com")
Here is the output of the script:
start service
started
http://localhost:50506
{'browserName': 'chrome', 'goog:chromeOptions': {'args': ['--no-sandbox', '--disable-dev-shm-usage'], 'binary': '/Applications/Enterprise.app/Contents/MacOS/Enterprise', 'extensions': [], 'windowTypes': ['webview']}, 'platform': 'ANY', 'version': ''}
And after about 1 min, the app closed and the script shows:
Traceback (most recent call last):
File "/Users/leo.wong/auto/Auto/try/try4.py", line 31, in <module>
keep_alive=False)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
I have tried similar code in Java and Javascript with Spectron which is mentions on Electron official website. But I'm seeing the same thing.
My Environment:
- MacOS: 10.14.6
- Python: 3.7
- Chrome: Version 79.0.3945.88 (Official Build) (64-bit)
- Chromedriver: ChromeDriver 79.0.3945.36
Anyone has an idea how I can get it to work and I would like to provide more info but please let me know what I should provide.