我的網頁只能在IE中使用,因爲它在javascript中使用ActiveXObject。 編寫內部工具測試此網頁時,如何指定瀏覽器類型和版本?如何指定在Java中使用Selenium lib時要模擬哪個瀏覽器?
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() {
\t \t try {
\t \t var variable_name;
\t \t \t variable_name=new ActiveXObject("Microsoft.XMLHTTP");
\t \t \t document.getElementById("demo").innerHTML = "ActiveXObject is created";
\t \t }
\t \t catch(err) {
\t \t \t document.getElementById("demo").innerHTML = err.message;
\t \t }
}
</script>
<input type="Button" id="test" value="Test" onClick='test()'>
<div id = "demo">blah</div>
</body>
</html>
另請參見http://www.guru99.com/introduction-to-selenium-grid.html – Jagdeep