这是
https://accounts.google.com/signin使用您的有效凭据访问url 登录并
PageTitle在控制台上打印的代码块:
String url = "https://accounts.google.com/signin";driver.get(url);driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement email_phone = driver.findElement(By.xpath("//input[@id='identifierId']"));email_phone.sendKeys("your_email");driver.findElement(By.id("identifierNext")).click();WebElement password = driver.findElement(By.xpath("//input[@name='password']"));WebDriverWait wait = new WebDriverWait(driver, 10);wait.until(ExpectedConditions.elementToBeClickable(password));password.sendKeys("your_password");driver.findElement(By.id("passwordNext")).click(); System.out.println(driver.getTitle());driver.quit();控制台输出:
Google Accounts
更新(2020年1月5日)
优化上面的代码块并添加几个可以使用的参数:
public class browserAppDemo { public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.setExperimentalOption("useAutomationExtension", false); options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation")); WebDriver driver = new ChromeDriver(options); driver.get("https://accounts.google.com/signin") new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("emailID"); driver.findElement(By.id("identifierNext")).click(); new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("password"); driver.findElement(By.id("passwordNext")).click(); }}


