Reputation: 116
I'm trying to load an extension(Metamask) into chrome to do some automated stuff. It works just fine on on my gaming grade rig, but both my laptop as well as my technical outdated homeserver pc timeout:
opt = webdriver.ChromeOptions() opt.binary_location = self.chrome_exe_location opt.add_argument('--log-level=3') opt.add_argument('--start-maximized') opt.add_experimental_option('excludeSwitches', ['enable-logging']) opt.add_extension(os.path.join(os.getcwd(), '10.9.3_0.crx')) self.driver = webdriver.Chrome(self.chromedriver_exe_location, options=opt, service_args='')
Traceback (most recent call last): File "C:\OneDrive\CloudDesktop\Python\main.py", line 968, in bot() File "C:\OneDrive\CloudDesktop\Python\main.py", line 69, in init self.chrome_initialize() File "C:\OneDrive\CloudDesktop\Python\main.py", line 118, in chrome_initialize self.driver = webdriver.Chrome(self.chromedriver_exe_location, options=opt, service_args='') File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in init super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in init RemoteWebDriver.init( File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 269, in init self.start_session(capabilities, browser_profile) File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 425, in execute self.error_handler.check_response(response) File "C:\OneDrive\CloudDesktop\Python\vEnv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.html from timeout: Timed out receiving message from renderer: 10.000
I guess this timeout occurs because selenium does not wait until the expansion is fully loaded or transferred. The .crx is about 18MB in size and I'd say the computer on which it's working takes about 5 secs and both other ones about 30 secs.
I already tinkered with selenium timeouts, but I found it's a lost cause, because I really can just set these parameters after the selenium object is created, which causes this timeout in the first place.
Does anyone of you guys know a way how selenium allows the startup process some more time?
Thanks for your help!
Upvotes: 0
Views: 2232
Reputation: 76
In the official Google Chrome support for chromedriver, there were some suggestions to use options.add_experimental_option('extensionLoadTimeout', 60000)
.
The time specified is in milliseconds, so 60 thousand corresponds to a timeout of one minute. This fixes timeout problems for slow PCs.
Upvotes: 1
Reputation: 116
I found a workaround:
Download extension in a normal use instance of chrome.
chrome://version/ copy profile path e.g. C:\Users\pcuser\AppData\Local\Google\Chrome\User Data\Default
Python code:
profile_path = r'C:\\Users\\pcuser\\AppData\\Local\\Google\\Chrome\\User Data'
opt.add_argument('--user-data-dir={}'.format(profile_path)) # profile path
opt.add_argument('--profile-directory={}'.format('DEFAULT')) #profile name
self.driver = webdriver.Chrome(self.chromedriver_exe_location, options=opt, service_args='')
self.driver.set_page_load_timeout(60) # adapt as you see fit
self.driver.set_script_timeout(60) # adapt as you see fit
self.driver.implicitly_wait(60) # adapt as you see fit
Upvotes: 0