0

I want to open the site www.flock.co and enter a email in the text field.However the program only opens the site and doesnt enter the email in the field.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FindByClassName {

    public static void main(String[] args) throws Exception {
        System.setProperty("webdriver.gecko.driver", "C:\\Automation\\geckodriver-v0.15.0-win64\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("https://flock.co/");

        driver.findElement(By.className("_g-s-wrap")).sendKeys("farzan.s@flock.co");
    }

}
Shaikh Farzan
  • 73
  • 1
  • 10

4 Answers4

1

_g-s-wrap is the class of a container that includes more features (like the "Get Started" button). Use cssSelector to locate the <input> textbox

driver.findElement(By.cssSelector("[type='email']")).sendKeys("farzan.s@flock.co");
Guy
  • 46,488
  • 10
  • 44
  • 88
1

There are many ways in which you can enter the email into a text field.

  1. using id
  2. using name
  3. xpath
  4. using css selector

there are other ways too but these are the very reliable and frequently used methods.

syntax for the methods are:

    driver.findElement(By.xpath(".//*[@id='main-area']/div[2]/div[2]/form/div/div[1]/input")).sendkeys("abc@gmail.com");

    driver.findElement(By.id("give the id of the editbox by inspecting element")).sendkeys("abc@gmail.com");

    driver.findElement(By.name("give the name of the editbox by inspecting element")).sendkeys("abc@gmail.com");
1

Sorry I pasted it wrong please try this

driver.findElement(By.xpath="//*[@id="main-area"]/div[3]/div‌​[2]/form/div/div[1]/‌​input").sendkeys("ex‌​ample@example.com"); 
mohamed faisal
  • 177
  • 2
  • 12
0

Pls use following code:-

  WebElement ele1 = driver.findElement(By.xpath("//input[@type='email']"));
   ele1.sendKeys("farzan.s@flock.co");
Deepak
  • 110
  • 2
  • 16