1

私の Web ページは、JavaScript で ActiveXObject を使用しているため、IE でのみ機能します。この Web ページをテストするために社内ツールをコーディングする場合、ブラウザーの種類とバージョンを指定するにはどうすればよいですか?

Java コードは次のとおりです。

package main; 

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class Temp  {
    public static void main(String[] args) {
        // Create a new instance of the html unit driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new HtmlUnitDriver();

        // And now use this to visit my web page
        driver.get("http://www.test.com:8000");
        
        // Find the text input element by its id
        driver.findElement(By.id("test")).click();
        driver.manage().timeouts().implicitlyWait(300,TimeUnit.SECONDS); 

        // Check the title of the page
        System.out.println("Result is: " + driver.findElement(By.id("demo")).getText());
        driver.quit();
    }
}

ウェブページは次のとおりです。

<html>
<body>
<script>
      function test() {    
		try {
		var variable_name;
			variable_name=new ActiveXObject("Microsoft.XMLHTTP");
			document.getElementById("demo").innerHTML = "ActiveXObject is created";
		}
		catch(err) {
			document.getElementById("demo").innerHTML = err.message;
		}
      }
    </script>
<input type="Button" id="test" value="Test" onClick='test()'>
<div id = "demo">blah</div>
</body>
</html>

4

2 に答える 2