IeDriverServer, WebDriver and Python

I personally don’t care about IE; however, clients do so I had to figure out the story around the new-ish IeDriverServer.exe for Python. For those also not caring about IE, the way the browser is controlled has moved towards the model that Opera and Chrome use which is a separate binary that can be iterated on outside of the client language bindings and Selenium Server.

And since this is WebDriver, there are actually two stories to be learned…

If you are running WebDriver then there 3 different ways to tell the binding where the server is locally. Which you use is entirely based on your own preference. (I think I like the first one which would actually be fed from some configuration file/object so would be system neutral.)

  1. The first way is to tell give the location in the constructor of the browser instance. One trick here though is to remember to escape those slashes. Especially if you are using a directory that starts with one of the magic letters – like t. Only took an hour to figure that one out…
    from selenium.webdriver import Ie
    driver = Ie(executable_path="c:\\temp\\IEDriverServer.exe")
    # do stuff
    driver.quit()
  2. The second way is to put the driver somewhere in the Path.
    from selenium.webdriver import Ie
    import sys
    sys.path.append('c:\temp')
    driver = Ie()
    # do stuff
    driver.quit()
    del sys.path[-1]
  3. The last way is to set an environment variable that tells WebDriver where to find its server.
    from selenium.webdriver import Ie
    import os
    os.environ['webdriver.ie.driver'] = "c:\temp\IEDriverServer.exe"
    driver = Ie()
    # do stuff
    driver.quit()
  4. del os.environ[‘webdriver.ie.driver’]

Of course, if you are using Remote WebDriver, none of those things will work. Instead you need to start the Selenium Server something like this.

java -jar selenium-server-standalone-2.26.0.jar -Dwebdriver.ie.driver=c:\temp\IEDriverServer.exe

And then you just access things via the Selenium Server as you would normally.

(Oh, and all this applies to the Google Chrome driver as well, but instead of webdriver.ie.driver it is webdriver.chrome.driver.)

Post a Comment

Your email is never published nor shared. Required fields are marked *