Unable to enter a string in the text box. It just opens the browser

790 Views Asked by At

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("[email protected]");
    }

}
4

There are 4 best solutions below

0
Guy On BEST ANSWER

_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("[email protected]");
0
Deepak On

Pls use following code:-

  WebElement ele1 = driver.findElement(By.xpath("//input[@type='email']"));
   ele1.sendKeys("[email protected]");
1
karan reddy On

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("[email protected]");

    driver.findElement(By.id("give the id of the editbox by inspecting element")).sendkeys("[email protected]");

    driver.findElement(By.name("give the name of the editbox by inspecting element")).sendkeys("[email protected]");
0
mohamed faisal On

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‌​[email protected]");