我的网页只适用于 IE,因为它在 javascript 中使用 ActiveXObject。在编写内部工具来测试此网页时,如何指定浏览器类型和版本?
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>