2017-08-30 123 views
0

我能寫腳本給我的電子郵件地址到電子郵件元素。但一旦通過腳本點擊下一步,Google就會使用ajax動態地將該電子郵件元素替換爲密碼元素。這是我卡住的地方,將無法在該元素中提供密碼,也無法登錄。硒測試腳本通過新的AJAX登錄表登錄到谷歌帳戶

網址:https://accounts.google.com/signin/v2/identifier?flowName=GlifWebSignIn&flowEntry=ServiceLogin

請寫出硒測試腳本來實現這一目標。

+0

其中硒綁定您使用的? Selenium通過Java/Python/C#/ JavaScript/Ruby/Perl?我們可以看到你的代碼塊嗎? – DebanjanB

+0

分享你試過的代碼 –

+0

Selenium通過Java – pravat231

回答

1

這裏是代碼塊用你的有效憑據才能訪問URL https://accounts.google.com/signin登錄和打印您的控制檯上的Page Title

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 
0

下面的代碼對我的作品

 driver.get("https://accounts.google.com/signin/v2/identifier?flowName=GlifWebSignIn&flowEntry=ServiceLogin"); 
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 
    driver.findElement(By.name("identifier")).sendKeys("[email protected]"); 
    driver.findElement(By.xpath("//span[contains(.,'Next')]")).click(); 
    driver.findElement(By.name("password")).sendKeys("123456"); 
    WebDriverWait wait = new WebDriverWait(driver, 10); 
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(.,'Next')]"))); 
    element.click(); 

希望它會幫助你:)

0

使用下面的代碼是一樣的:

driver.findElement(By.id("identifierId")).sendKeys("[email protected]"); 
driver.findElement(By.id("identifierNext")).click(); 
System.out.println("Username Entered And Next Button clicked"); 
try 
{ 
    new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//input[@type='password']")))); 
    driver.findElement(By.xpath("//input[@type='password']")).sendKeys("testpassword"); 
} 
catch(Exception e) 
{ 
    new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//input[@type='password']")))); 
    driver.findElement(By.xpath("//input[@type='password']")).sendKeys("testpassword"); 

    driver.findElement(By.id("passwordNext")).click(); 
    System.out.println("Password Entered And Next Button clicked"); 
}