1.

What is an alternate way to click on the Login button?

Answer»

In selenium, we can click on the Login button in different ways -

1. Navigate to login button. Once control is on the login button perform click() ACTION.

package clicklogin;

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.interactions.Actions; public class LoginClick {          public static void main(String[] args) throws InterruptedException{                      WebDriver driver = new FirefoxDriver();                      //LAUNCHING site                      driver.get("http://facebook.com");                      // click on the LogIn button                       driver.findelement(By.id("u_0_a")).click();                      //Thread.sleep just to notice event                      Thread.sleep(3000);                      //Closing the driver instance                      driver.quit();          } }

2. ANOTHER way to perform click on Login button using action class

package clicklogin; 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.interactions.Actions; public class LoginClick {          public static void main(String[] args) throws InterruptedException{                      WebDriver driver = new FirefoxDriver();                      //Launching site                      driver.get("http://facebook.com");                      // click on the LogIn button             WebElement loginBtn = driver.findElement(By.id("u_0_a"));                      Actions act = new Actions(driver);                      act.moveToElement(loginBtn).click().perform().build();                         //Thread.sleep just to notice event                      Thread.sleep(3000);                      //Closing the driver instance                      driver.quit();          } }

3. Third way is PRESS Enter key

package clicklogin; 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.interactions.Actions; public class LoginClick {          public static void main(String[] args) throws InterruptedException{                      WebDriver driver = new FirefoxDriver();                      //Launching site                      driver.get("http://facebook.com");                      // click on the Log In button             WebElement loginBtn = driver.findElement(By.id("u_0_a"));                      Actions act = new Actions(driver);                      act.SendKeys(Keys.Enter);              //Thread.sleep just to notice event                      Thread.sleep(3000);                      //Closing the driver instance                      driver.quit();          } }


Discussion

No Comment Found