2

I'm trying to write a test script that will login to facebook, but it falls short of clicking the login button. Where did I go wrong here?

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();
 }
}

2 Answers 2

2

In webDriver we can do it like this

    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();
   }
Sign up to request clarification or add additional context in comments.

Comments

0

For chrome driver:

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();
   }

First make sure you have chrome driver with environment variable path. If you don't have, go to http://code.google.com/p/chromedriver/downloads/list. Download and set path. Use this for set path

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.