How to use DesiredCapabilities class through IEDriverServer in Selenium and Python How to use DesiredCapabilities class through IEDriverServer in Selenium and Python selenium selenium

How to use DesiredCapabilities class through IEDriverServer in Selenium and Python


You have to take care of a couple of facts as follows:

  • Instead of using DesiredCapabilities.INTERNETEXPLORER you need to use DesiredCapabilities.INTERNETEXPLORER.copy().

Note: Always append .copy() on the DesiredCapabilities object to avoid the side effects of altering the Global class instance.

  • As per the The Desired Capabilities implementation executablePath() is not any valid argument. Instead pass the argument executable_path when initializing the WebDriver/WebClient.
  • As you have added the option introduceFlakinessByIgnoringSecurityDomains(), as per the discussion in the blog You're Doing It Wrong: IE Protected Mode and WebDriver @JimEvans clearly mentioned that adding INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS may get you past the initial exception and will allow the test to run in most cases without incident. However using this capability doesn't solve the underlying problem though. If a Protected Mode Boundary is crossed, very unexpected behavior including hangs, element location not working, and clicks not being propagated, could occur.
  • As you are sending a character sequence to the Google Search Box instead of presence_of_element_located() method use element_to_be_clickable() method.

  • Here is your own code with a couple of modifications:

    from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECcap = DesiredCapabilities.INTERNETEXPLORER.copy()cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = Truedriver = webdriver.Ie(capabilities=cap, executable_path=r'C:\Utility\BrowserDrivers\IEDriverServer.exe')driver.get('https://google.com')search = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.NAME, 'q')))search.send_keys("selenium")search.submit()

Browser Snapshot

google_search_selenium_ie


Reference

Here you find a detailed discussion on Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 with Selenium 3.13.0: IEDriverServer_x64_3.13.0