I am trying to access some websites with different accounts, and to avoid logging in every time I am planning to make an user profile for each one. I am hosting my Python app on an Ubuntu server, so I have to run it headless, and I also need the mobile emulation. Here's a sample of what I'm trying to do:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_experimental_option("mobileEmulation", {"deviceName": "Pixel 2"})
options.add_argument("user-data-dir=account-data/account_3")
chromedriver = "./webdrivers/chrome"
driver = webdriver.Chrome(executable_path=chromedriver, options=options)
print("START SEARCH")
# Google is an example, but nothing works
driver.get("https://www.google.com")
print("FINISHED")
I see START SEARCH but never FINISHED. When I comment the user-data-dir options, however, everything works perfectly. The weird thing is that this happens on an Ubuntu 20 LTS server, but in my Mac it has no issues.
While trying to get the versions for this question, out of the blue the version that doesn't work started giving me this:
Traceback (most recent call last):
File "seleniumtest.py", line 12, in <module>
driver = webdriver.Chrome(executable_path=chromedriver, options=options)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/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
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 5.4.0-1009-kvm x86_64)
The only thing I've really done before getting this error is deleting all the /tmp/.org.chromium.Chromium.* files but those should only be temporary files and new ones should be created all the time when I don't specify the user-data-dir flag.