我想打开网站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");
}
}
答案 0 :(得分:1)
_g-s-wrap
是包含更多功能的容器类(如“Get Started”按钮)。使用cssSelector
找到<input>
文本框
driver.findElement(By.cssSelector("[type='email']")).sendKeys("farzan.s@flock.co");
答案 1 :(得分:1)
您可以通过多种方式将电子邮件输入文本字段。
还有其他方法,但这些是非常可靠和经常使用的方法。
方法的语法为:
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");
答案 2 :(得分:1)
抱歉我粘贴错了请试试这个
driver.findElement(By.xpath="//*[@id="main-area"]/div[3]/div[2]/form/div/div[1]/input").sendkeys("example@example.com");
答案 3 :(得分:0)
请使用以下代码: -
WebElement ele1 = driver.findElement(By.xpath("//input[@type='email']"));
ele1.sendKeys("farzan.s@flock.co");