Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package open_website;
- import java.util.List;
- import org.junit.Assert;
- import java.util.concurrent.TimeUnit;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.remote.DesiredCapabilities;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class FacebookLogin {
- public static void main(String[] args) {
- WebDriver driver;
- DesiredCapabilities cap=DesiredCapabilities.firefox();
- driver=new FirefoxDriver(cap);
- driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
- driver.manage().window().maximize();
- driver.get("https://www.facebook.com");
- String username = "Enter your username here";
- String pwd = "Enter your password here";
- WebElement email = driver.findElement(By.id("email"));
- email.sendKeys(username);
- WebElement password = driver.findElement(By.id("pass"));
- password.sendKeys(pwd);
- WebElement login = driver.findElement(By.id("u_0_r"));
- login.click();
- System.out.println("User is logged in");
- String helloWorld = "Hello World";
- WebElement status = driver.findElement(By.xpath("//*[@name='xhpc_message']"));
- status.sendKeys(helloWorld);
- WebDriverWait wait = new WebDriverWait(driver, 5);
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='Post']")));
- WebElement postButton = driver.findElement(By.xpath("//*[text()='Post']"));
- postButton.click();
- System.out.println("Posted the status message '" + helloWorld + "' successfully");
- try {
- Thread.sleep(10000); //Sleep for 10 seconds
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- //Verifying that the status message is present.
- List<WebElement> list = driver.findElements(By.xpath("//*[contains(text(),'" + helloWorld + "')]"));
- Assert.assertTrue("Status message '" + helloWorld +"' not posted!", list.size() > 0);
- driver.quit(); //Closes all browser windows and safely ends the session.
- }
- }
Add Comment
Please, Sign In to add comment