[JAVA] Summary of problems and countermeasures when operating IE with WebDriver of Selenium2

I introduced Selenium because the on-site team I was seconded to manually created test data on the screen. Since the system I am in charge of works only with IE, I do not make test cases with IDE I implemented the case in java using WebDriver and operated the browser. It also serves as a memorandum and summarizes problems and usage.

environment

windows10 64bit IE11 java 1.8.0_121 eclipse Neon.2 Release (4.6.2) selenium 2.53.1

Setting

  1. Create a new maven project in eclipse Check "Create a simple project" when creating

  2. Modify pom.xml

pom.xml excerpt


<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
</dependencies>
  1. Download IEDriverServer From here
  1. To Java implementation You need to setProperty the path of DriverServier obtained in 3.

How to write IEDriver initial settings


System.setProperty("webdriver.ie.driver","C:\\Any place\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
Here is a reference for how to use the driver

Problem and response

1. Selenium startup error

python


Unexpected error launching Internet Explorer. 
Protected Mode must be set to the same value (enabled or disabled) for all zones.

IE browser Internet Options → Security tab settings → Make the protection mode setting the same for all zones

2. sendKeys is very slow

Sendkeys for entering browser text is unusually slow to use I have not investigated the detailed cause, but it seems to be the case when using the 64-bit version of IEDriverServer.

3. Does not ignite even if clicked

It seems to occur occasionally in IE. I was able to avoid it with the following description.

python


WebElement element = driver.findElement(clickTarget);
element.sendKeys(Keys.CONTROL);
element.click();
Or
new Actions(driver).click(element).build().perform();

4. Stop when the file download pop-up appears

Pop-up (notification bar) that appears when you download a file in IE When that happens, selenium will stop. It doesn't work even if I click it manually. With IE11, I couldn't change the settings from the browser. Therefore, create a child thread and leave the download process to that. The parent thread is working hard to keep the main processing going.

Tips

I want to operate the child screen of the browser

When the parent screen creates a child screen with JS How to do when you want to focus on the sub screen and operate it.

python


//Hold parent window information
String currentHandle = driver.getWindowHandle();

//Switch focus to child window
Set<String> windowHandles = driver.getWindowHandles();
  for (String handle : windowHandles) {
    if (!handle.equals(currentHandle)) {
      driver.switchTo().window(handle);
    }
}

//Return to parent when child window processing is finished
driver.switchTo().window(currentHandle);

I want to wait until the browser finishes processing

After ordering an operation with Selenium, I want to wait until it finishes. For example, after searching, I want to perform the following operation after the search is completed and the list appears. The following sources wait for the element with id list to appear on the screen. The timeout is 10 seconds, and an exception occurs when it is exceeded.

python


//Standby object
WebDriverWait wait = new WebDriverWait(driver, 10);

wait.until(
  ExpectedConditions.presenceOfElementLocated(
    By.id("list")
  )
);

I want to upload a file

python


WebElement element = driver.findElement(By.xpath("//input[@type='file']"));
element.sendKeys("./File.txt");

References

https://donow.jp/skillup/?p=776#i-7 http://qiita.com/tukiyo3/items/44f5b64cf222d9da1b5b http://bokuibi.blogspot.jp/2012/05/selenium-2.html http://qiita.com/nkns165/items/53d1afc17023d9ae3ebd

Recommended Posts

Summary of problems and countermeasures when operating IE with WebDriver of Selenium2
Summary of problems and countermeasures when operating IE with WebDriver of Selenium2
Read xlsx file in Java with Selenium
Run Edge (Chromium version) on Mac with Selenium
Summary of ToString behavior with Java and Groovy annotations
Summary of how to use the proxy set in IE when connecting with Java
[Rails] N + 1 problems and countermeasures
Summary of what we did to make JavaScript compatible with IE11
[JVM] Summary when stumbling with jstat
Summary of means when you want to communicate with HTTP on Android