How to click on sign up button using Java in Selenium I am able to open page but not able to click?


We can click on the Sign up button using Java in Selenium. First of all, we have to identify the Sign up button with the help of any of the locators like id, class name, name, link text, xpath, css or partial link text. After identification, we have to click on the Sign up the button with the help of the method click.

Syntax

WebElement m=driver. findElement(By.id("loc-txt"));
m.click();

Example

Code Implementation with click

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class SignIn{
   public static void main(String[] args) {
      System.setProperty("webdriver.gecko.driver",
         "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");
      WebDriver driver = new FirefoxDriver();
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("https://www.linkedin.com/");
      // identify element with class name then use click method
      WebElement m=driver.
      findElement(By.className("sign-in-form__submit-button"));
      m.click();
      driver.close();
   }
}

Also, we can click on the Sign up button with the help of the sendKeys method and pass Keys.ENTER as a parameter to that method.

Syntax

WebElement m=driver. findElement(By.id("loc-txt"));
m.sendKeys(Keys.ENTER);

Example

Code Implementation with sendKeys

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Keys;
public class SignInSendKeys{
   public static void main(String[] args) {
      System.setProperty("webdriver.gecko.driver",
         "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");
      WebDriver driver = new FirefoxDriver();
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("https://www.linkedin.com/");
      // identify element with class name then use sendKeys method
      WebElement m=driver.
      findElement(By.className("sign-in-form__submit-button"));
      m.sendKeys(Keys.ENTER);
      driver.close();
   }
}

Updated on: 06-Apr-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements