Shaikh Farzan
Shaikh Farzan

Reputation: 83

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

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]");
    }

}

Upvotes: 0

Views: 790

Answers (4)

mohamed faisal
mohamed faisal

Reputation: 177

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]"); 

Upvotes: 1

karan reddy
karan reddy

Reputation: 11

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]");

Upvotes: 1

Deepak
Deepak

Reputation: 100

Pls use following code:-

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

Upvotes: 0

Guy
Guy

Reputation: 50854

_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]");

Upvotes: 1

Related Questions