2

我正在尝试编写一个将登录到 facebook 的测试脚本,但它没有单击登录按钮。我在这里哪里做错了?

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class GoogleRobotSearch {
 private Selenium sel;

 public GoogleRobotSearch () {
  sel = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
  sel.start();
 }

 public void search() {
  sel.open("http://www.facebook.com");
  sel.type("id=email","email");
  sel.type("id=pass","password");
  //sel.waitForPageToLoad("5000");
    sel.click("//input[@value='Log In']");
 }

 public static void main (String args[]) {
  GoogleRobotSearch xybot = new GoogleRobotSearch ();
  xybot.search();
 }
}
4

2 回答 2

2

在 webDriver 我们可以这样做

    public static void main(String[] args) 
   {
    WebDriver driver=new FirefoxDriver();
    driver.get("https://www.facebook.com/");
    driver.findElement(By.id("email")).sendKeys("mail");
    driver.findElement(By.id("pass")).sendKeys("pwd");
    driver.findElement(By.id("loginbutton")).click();
   }
于 2013-07-05T12:30:49.093 回答
0

对于 chrome 驱动程序:

public static void main(String[] args) 
   {
    WebDriver driver= new ChromeDriver();
    driver.get("https://www.facebook.com/");
    driver.findElement(By.id("email")).sendKeys("mail");
    driver.findElement(By.id("pass")).sendKeys("pwd");
    driver.findElement(By.id("loginbutton")).click();
   }

首先确保您有带有环境变量路径的 chrome 驱动程序。如果您没有,请访问http://code.google.com/p/chromedriver/downloads/list。下载并设置路径。将此用于设置路径

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
于 2014-04-22T07:40:11.800 回答