Operate IE with C # and Selenium

less than 1 minute read

Introduction

I’m sorry to talk about IE even though 2020 is already September.

Selemium is a product for realizing browser automation, but I will summarize how to operate IE using it. It fits a little …

I will not touch on the full-scale usage of Selemium. It is only a point for operating IE.

Preparation: Check IE settings

Open IE and enable the protected mode of each zone from the “Security” tab of “Internet Options”.

image.png

By default, it is disabled for local intranets and trusted sites, but enable “all” protection mode. If you make only partial changes, you will get an exception when running Selemium.

After that, open the “Advanced tab” and make sure that “Enable extended protection mode *” is not checked.

image.png

If it is checked, uncheck it and restart your PC.

Operate IE with Selenium

First create a project and install the following two libraries from NuGet.

  • Selenium.WebDriver
  • Selenium.WebDriver.IEDriver

Then, let’s implement and execute as follows.

var driver = new InternetExplorerDriver();

driver.Navigate().GoToUrl("https://www.google.co.jp/");

var textBox = driver.FindElement(By.Name("q"));
textBox.SendKeys("Selenium");

var button = driver.FindElement(By.Name("btnK"));
button.Click();

This should launch IE and perform a search with the keyword Selemium after transitioning to Google.

that’s all.