Selenium test with Python in Internet Explorer
Question:
I have written a script that opens a web browser using python and Selenium. It works fine with Firefox using the following code:
from selenium import webdriver
driver = webdriver.Firefox()
When I replace Firefox with IE (the suggested value when I start typing), I get the message IEDriver executable needs to be available in the path.
from selenium import webdriver
driver = webdriver.IE()
Answers:
-
Download IE Drivers based on your OS (Windows 32 or 64 bit)
a. Download Windows 32 bits driver
OR
b. Download Windows 64 bits driver
-
Extract the zip and copy IEDriverServer.exe file to some location e.g. E:IEDriver
-
Write the following script
from selenium import webdriver
browser = webdriver.Ie("e:\IEDriver\IEDriverServer.exe")
-
Run the script, it should open IE browser…
Selenium with Python bindings in IE:
There are 2 ways to run Selenium python tests in Internet Explorer. I’m considering Windows (Windows 10 in my case):
Prerequisite: Download IE Driver based on your OS from the site: http://docs.seleniumhq.org/download/
Way 1:
i) Extract the downloaded zip file in a directory/location of your choice
ii) Set the executable path in your code as below:
self.driver = webdriver.Ie(executable_path='D:Selenium_RiponAlWasimDriversIEDriverServer_x64_2.42.0IEDriverServer.exe')
OR,
self.driver = webdriver.Ie("D:\Selenium_RiponAlWasim\DriversIEDriverServer_x64_2.42.0\IEDriverServer.exe")
Way 2:
i) Simply paste the IEDriverServer.exe under /Python/Scripts/ (In my case the folder was: C:Python36Scripts)
ii) Now write the simple code as below:
self.driver = webdriver.Ie()
In selenium 4 you would need to use service method otherwise you would get depreciated error: You no longer need to download IE driver.
Here are compatible codes for Selenium 4.x IE:
# Internet Explorer Browser version
from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.microsoft import IEDriverManager
driver = webdriver.Ie(service=Service(executable_path=IEDriverManager().install()))
driver.get('https://www.google.com')
I have written a script that opens a web browser using python and Selenium. It works fine with Firefox using the following code:
from selenium import webdriver
driver = webdriver.Firefox()
When I replace Firefox with IE (the suggested value when I start typing), I get the message IEDriver executable needs to be available in the path.
from selenium import webdriver
driver = webdriver.IE()
-
Download IE Drivers based on your OS (Windows 32 or 64 bit)
a. Download Windows 32 bits driver
OR
b. Download Windows 64 bits driver
-
Extract the zip and copy IEDriverServer.exe file to some location e.g. E:IEDriver
-
Write the following script
from selenium import webdriver browser = webdriver.Ie("e:\IEDriver\IEDriverServer.exe")
-
Run the script, it should open IE browser…
Selenium with Python bindings in IE:
There are 2 ways to run Selenium python tests in Internet Explorer. I’m considering Windows (Windows 10 in my case):
Prerequisite: Download IE Driver based on your OS from the site: http://docs.seleniumhq.org/download/
Way 1:
i) Extract the downloaded zip file in a directory/location of your choice
ii) Set the executable path in your code as below:
self.driver = webdriver.Ie(executable_path='D:Selenium_RiponAlWasimDriversIEDriverServer_x64_2.42.0IEDriverServer.exe')
OR,
self.driver = webdriver.Ie("D:\Selenium_RiponAlWasim\DriversIEDriverServer_x64_2.42.0\IEDriverServer.exe")
Way 2:
i) Simply paste the IEDriverServer.exe under /Python/Scripts/ (In my case the folder was: C:Python36Scripts)
ii) Now write the simple code as below:
self.driver = webdriver.Ie()
In selenium 4 you would need to use service method otherwise you would get depreciated error: You no longer need to download IE driver.
Here are compatible codes for Selenium 4.x IE:
# Internet Explorer Browser version
from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.microsoft import IEDriverManager
driver = webdriver.Ie(service=Service(executable_path=IEDriverManager().install()))
driver.get('https://www.google.com')