Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (38 sloc) 1.47 KB

利用Web Ghost实现和WebDriverThe 5 Minute Getting Started Guide实例相同的效果。

var Ghost = require('webghost');

var ghost = new Ghost(); // 打开浏览器
.go("") // 访问Google
.val('input[name="q"]', "Cheese!") // 输入Cheese!
.submit("#tsf") // 提交表单
.await(1000) // 暂停1秒,等待跳转
.getTitle(function (title) {
  console.log("Page title is: " + title); // 打印标题


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

public class Example  {
    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 Google

        // Find the text input element by its name
        WebElement element = driver.findElement("q"));

        // Enter something to search for

        // Now submit the form. WebDriver will find the form for us from the element

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());