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.
Related
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
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
Here's my code and the error Python provides.
I'm a beginner using Python 3.6. Can anyone helps find out what's wrong? Many thanks.
#!/usr/bin/env python
#coding: utf-8
from selenium import webdriver
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
browser = webdriver.Chrome()
browser.get('http://www.bing.com/')
Traceback:
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\cxy61.com - html\python spider\001 selenium import.py", line 8, in <module>
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception: Chrome version must be >= 58.0.3029.0
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.14393 x86_64)
You have to take care of a couple of things as follows:
As you are using chromedriver v2.31 the error clearly states Chrome version must be >= 58.0.3029.0. So you need to bump up your Google Chrome version to v58.0 or above.
If you want to specify the absolute path of the chromedriver within single quotes '...' then you have to provide single forward slashes \ only.
If you are assigning the webdriver instance to the driver, you have to use the driver instance only to open any url
Here is your own code with the above mentioned changes:
from selenium import webdriver
driver = webdriver.Chrome(r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('http://www.bing.com/')
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.
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 :)