简体   繁体   中英

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("farzan.s@flock.co");
    }

}

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

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

对不起,我粘贴错了,请尝试这个

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

Pls use following code:-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM