0

我想打开网站 www.flock.co 并在文本字段中输入电子邮件。但是该程序仅打开该网站而没有在该字段中输入电子邮件。

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

}
4

4 回答 4

1

_g-s-wrap是包含更多功能(如“开始”按钮)的容器类。用于cssSelector定位<input>文本框

driver.findElement(By.cssSelector("[type='email']")).sendKeys("farzan.s@flock.co");
于 2017-04-16T10:41:08.407 回答
1

您可以通过多种方式将电子邮件输入到文本字段中。

  1. 使用身份证
  2. 使用名称
  3. 路径
  4. 使用 CSS 选择器

还有其他方法,但这些是非常可靠且经常使用的方法。

这些方法的语法是:

    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");
于 2017-04-16T18:30:05.967 回答
1

抱歉我贴错了请试试这个

driver.findElement(By.xpath="//*[@id="main-area"]/div[3]/div‌​[2]/form/div/div[1]/‌​input").sendkeys("ex‌​ample@example.com"); 
于 2017-05-08T10:14:17.537 回答
0

请使用以下代码:-

  WebElement ele1 = driver.findElement(By.xpath("//input[@type='email']"));
   ele1.sendKeys("farzan.s@flock.co");
于 2017-04-16T11:02:39.437 回答