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
Chrome and chromedriver versions 98.0.4758.102 64bit on all computers
Python versions 3.10.1(one pc working and one desn't) and 3.10.2(not
working)
OS: Win 10(none working) and 11(working) all updated
CPU:5600x(working), Snapdragon 8cx(not working),Intel Celeron J3455(not working)
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!
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.
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
Related
When dealing with some memory issues, my script was interrupted and now it will not restart. I am getting an error "selenium.common.exceptions.SessionNotCreatedException: Message: session not created from tab crashed (Session info: headless chrome=84.0.4147.135)"
I read a few other similar questions (this one is almost identical), but the solutions do not resolve my problem.
Here is my code:
from selenium import webdriver
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--remote-debugging-port=9222")
chromeOptions.add_argument('--no-sandbox')
chromeOptions.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US',
"download.default_directory": download_location,
"download.directory_upgrade": True})
webdriver_location = '/usr/bin/chromedriver'
driver = webdriver.Chrome(webdriver_location,options=chromeOptions)
I attempted to add the chromeOptions.add_argument('--disable-dev-shm-usage') and received the same error.
Because the setup was running perfectly moments before and no updates have been done, I do not believe any versioning is the problem. I'm running on a Centos 7 server. I originally received the error with Google Chrome 84 and Chromedriver 84. Same error occurs when upgrading both to 85.
Here is the full error:
Traceback (most recent call last):
File "server_scraper_javascript_v2.py", line 323, in <module>
driver = webdriver.Chrome(webdriver_location,options=chromeOptions)
File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from tab crashed
(Session info: headless chrome=84.0.4147.135)
UPDATE:
I do not have experience using Chromium without Selenium and a webdriver, but if I run chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com/, it fails and I receive this:
#
# Fatal error in , line 0
# Fatal process out of memory: Failed to reserve memory for new V8 Isolate
#
#
#
#FailureMessage Object: 0x7ffc0fc7ed50#0 0x5619c34ebdd9 <unknown>
--2020-08-27 10:20:27-- https://clients2.google.com/cr/report
Resolving clients2.google.com (clients2.google.com)... 172.217.165.142, 2607:f8b0:4006:808::200e
Connecting to clients2.google.com (clients2.google.com)|172.217.165.142|:443... connected.
HTTP request sent, awaiting response... [0827/102028.181052:ERROR:headless_shell.cc(391)] Abnormal renderer termination.
200 OK
Length: unspecified [text/plain]
Saving to: ‘/dev/fd/4’
0K Crash dump id: 80939f7cd5646339
I recently ran into this issue where a script I call regularly was working, and then failed with the same "session not created from tab" error. I hadn't updated chrome or the chromedriver so the other solutions I found didn't work. I found that the issue was that I wasn't quitting the browsers at the end of my script so they were all still active.
I checked the active pid's for chrome with pgrep chrome and saw that I had a bunch of chrome processes running. I killed them all with pkill chrome and that fixed the issue. I added driver.quit() to the end of the script to kill the browser when it's done.
I'm not sure if that will solve your issue, but the memory error you got when trying to run google-chrome --headless made me think it might be the same issue I had.
I created a script in Python, which scraps the Altium's website and gathers information regarding license usage. At this moment, I am using ChromeDriver, but I sometimes get errors due to the network being slow at different times of the day. I used the same script using the MicrosoftWebDriver (Edge) on my Personal Computer and I received no errors. When you launch the MicrosoftWebDriver.exe (downloaded from their website) it should open Edge, but when I use my company's laptop, nothing happens (see attached picture).
Is there any chance I can fix this? Is this happening as a result of the port being blocked?
This is the code I am using for selecting the webdriver:
browser = webdriver.Edge(r'C:\ALTIUM_WORK\Altium_Python\MicrosoftWebDriver.exe')
And this is the "error" I get:
And nothing happens after this...
The Python's Shell says this:
Traceback (most recent call last):
File "C:\ALTIUM_WORK\Altium_Python\Altium_H1.py", line 172, in <module>
browser = webdriver.Edge(r'C:\ALTIUM_WORK\Altium_Python\MicrosoftWebDriver.exe')
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 66, in __init__
desired_capabilities=capabilities)
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: Unknown error
You need to pass the argument executable_path as follows:
browser = webdriver.Edge(executable_path=r'C:\ALTIUM_WORK\Altium_Python\MicrosoftWebDriver.exe')
This what solved the problem...
Local Security Policy -> Local Policies -> Security Options -> User Account Control: Run all administrators in Admin Approval Mode -> ENABLED
browser = webdriver.Edge(r'C:\ALTIUM_WORK\Altium_Python\MicrosoftWebDriver.exe')
This is not working because in your office laptop User Account Control settings is Turned Off.
You need turned On User Account Control settings and restart your machine and then run your code.It will work as expected.
To go to path on OS :
Control Panel-->All Control Panel Items-->User Accounts--> Change User Account Control settings
I am running on a Windows 10 machine, Internet Explorer 11, python 3.6, selenium 3.4.3 with IEDriverServer 3.5. I am trying to open up IE using the following code.
from selenium import webdriver
import os
driverLocation = "C:\\Users\\JD\\PycharmProjects\\Lib\\IEDriverServer.exe"
os.environ["webdriver.ie.driver"] = driverLocation
driver = webdriver.Ie(driverLocation)
google = "https://google.com"
driver.get(google)
The output:
Traceback (most recent call last):
File "C:/Users/J/PycharmProjects/Automation/IE_Test.py", line 7, in <module>
driver = webdriver.Ie(driverLocation)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 57, in __init__
desired_capabilities=capabilities)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Invalid capabilities in alwaysMatch: unknown capability named platform
Any help would be greatly appreciated thanks.
UPDATE:
I added this to my previous code,
capabilities = DesiredCapabilities.INTERNETEXPLORER
print(capabilities["platform"])
print(capabilities["browserName"])
OUTPUT:
WINDOWS
internet explorer
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Invalid capabilities in alwaysMatch: unknown capability named platform
UPDATE:
I have also tried setting the capabilities but still recieve the same error: "unknown capabilities named platform
caps = DesiredCapabilities.INTERNETEXPLORER.copy()
caps["platform"] = "WINDOWS"
caps["browserName"] = "internet explorer"
caps["requireWindowFocus"] = True
browser = webdriver.Ie(capabilities=caps,
executable_path="C:\\Users\\JD\\PycharmProjects\\Lib\\IEDriverServer.exe")
browser.get("https://www.facebook.com/")
I had the same problem for couple of days.
My workaround for this was to delete platform and version keys from capabilities dictionary
Example:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
#create capabilities
capabilities = DesiredCapabilities.INTERNETEXPLORER
#delete platform and version keys
capabilities.pop("platform", None)
capabilities.pop("version", None)
#start an instance of IE
driver = webdriver.Ie(executable_path="C:\\your\\path\\to\\IEDriverServer.exe", capabilities=capabilities)
driver.get("https://www.google.com/")
My guess, so far, is that this error happens because w3c_caps are passed as the only right capabilities. You can see that in the Traceback:
response = self.execute(Command.NEW_SESSION, parameters)
when you click on it you will see that:
w3c_caps["alwaysMatch"].update(capabilities)
As you can see here _W3C_CAPABILITY_NAMES hold different values than the ones we are passing.
We are passing "WINDOWS" as "platform", while _W3C_CAPABILITY_NAMES has "platformName" and accepts only small caps. Same goes for "version" key.
So we were adding capabilities that are not recognized.
This workaround is by no means perfect, and I was able to start IE in selenium java without deleting some of the capabilities.
EDIT: Another solution can be found here in Grimlek comment, which essentially says that you should delete "capabilities": w3c_caps from start_session(self, capabilities, browser_profile=None) (from remote\webdriver.py). Code looks like this:
w3c_caps["alwaysMatch"].update(capabilities)
parameters = {"capabilities": w3c_caps,
"desiredCapabilities": capabilities}
Then you would not need to delete keys from capabilities.
ANOTHER EDIT: I have just updated my selenium-python from 3.4.3 to 3.5.0 and there's no longer need for messing with capabilities.
I am using Selenium to automate the Web page test with IE11, I did all of the steps following the instruction from https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration, but still error when I run my automation, I have not been able to bring up IE browser yet.
(For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Inside this key, create a DWORD value named iexplore.exe with the value of 0.)
Protected mode settings are the same for all zones
Enhanced Protected Mode is disabled.
Set Zoom level to 100%
But I still have not been able to bring up IE browser, I got following error:
======================================================================
ERROR: test_contact (__main__.IETestCases)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_ie.py", line 528, in setUp
IEDefault.setUp(self)
File "test_ie.py", line 88, in setUp
self.driver = webdriver.Ie(r'C:\Users\jzhao\WebPageTest\IEDriverServer_x64_3.4.0\IEDriverServer.exe')
File "C:\Python27\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 57, in __init__
desired_capabilities=capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response
raise exception_class(value)
WebDriverException: Message: Error 400: Bad Request
Invalid URI: [http://127.0.0.1:56761/session]
----------------------------------------------------------------------
Version:
Selenium 3.4.3
IE 11
Windows 7 64-bit
IEDriverServer_x64_3.4.0
Python 2.7.13
Here is the Answer to your Question:
While working with Selenium 3.4.0, IEDriverServer 3.4.0, IE 11 through Python 3.6.1 bindings, you can take help of the DesiredCapabilities class to make a few configuration to open IE 11 as follows:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().INTERNETEXPLORER
cap['platform'] = "Win8"
cap['version'] = "11"
cap['browserName'] = "internet explorer"
cap['ignoreProtectedModeSettings'] = True
cap['nativeEvents'] = False
cap['requireWindowFocus'] = True
cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
driver=webdriver.Ie(capabilities=cap, executable_path=r'C:\Utility\BrowserDrivers\IEDriverServer.exe')
driver.get("https://www.facebook.com/")
Let me know if this Answers your Question.
Suddenly my Python scripts on Selenium stop to launch because of following code and error:
from selenium import webdriver
dr = webdriver.Ie()*
*Actually new browser session opens on webdriver's default page but webdriver stop to respond so no other commands could be executed
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\me\AppData\Roaming\Python\Python34\site-packages\sele
nium\webdriver\ie\webdriver.py", line 57, in init
desired_capabilities=capabilities)
File "C:\Users\me\AppData\Roaming\Python\Python34\site-packages\sele
nium\webdriver\remote\webdriver.py", line 89, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\me\AppData\Roaming\Python\Python34\site-packages\sele
nium\webdriver\remote\webdriver.py", line 138, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Users\me\AppData\Roaming\Python\Python34\site-packages\sele
nium\webdriver\remote\webdriver.py", line 195, in execute
self.error_handler.check_response(response)
File "C:\Users\me\AppData\Roaming\Python\Python34\site-packages\sele
nium\webdriver\remote\errorhandler.py", line 170, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unexpected error launchi
ng Internet Explorer. Could not get document from window handle
IE version 11
IeWebDriverServer version 2.35 x64
Why this trace appeared? Maybe someone faced the same issue.. Any help will be appreciated
UPDATED
Resolved. Current IeWebDriverServer version replaced with v2.48
Check the following:
You are using the same security settings, for all the zones.
You are using the correct driver. Use the 32 bit when in doubt.
Make sure your registry settings are correct.
Zoom level is 100%.
Source: I am the creator of Germanium, an opensource testing API, and I support IE :)