简体   繁体   English

Java Selenium无法登录GMail

[英]Java Selenium can't login GMail

i am learning Selenium with java . 我正在用Java学习Selenium。 My use case is : 我的用例是:

  1. Browse www.Google.com 浏览www.Google.com
  2. Search for "Gmail Login" 搜索“ Gmail登录”
  3. open first link 打开第一个链接
  4. click on signin button (it will take me to login page) 单击登录按钮(这将带我进入登录页面)
  5. Enter email , click next then enter password 输入电子邮件,单击下一步,然后输入密码
  6. click next 点击下一步

There are two scenarios , one when i directly browse for gmail login page and skip (1,2,3 points ) it works for me . 有两种情况, one当我直接浏览gmail登录页面skip (1,2,3 points )它对我有用。 i can login but with 2nd when start from 1st step it Throws 我可以登录,但与2nd时从第一步开始就抛出

Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout at point 5 (when needs to enter email) Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout在点5 Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout (需要输入电子邮件时)

Here is my overall code : 这是我的整体代码:

  WebDriver web;
    public void invokeChrome()
    {
            System.setProperty("webdriver.chrome.driver", "D:\\software testing\\chromedriver.exe");
            web = new ChromeDriver();
            web.manage().window().maximize();
            web.manage().deleteAllCookies();
            web.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            web.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
            web.get("https://www.google.com");

    }
 void searchQuery() throws InterruptedException
   {
       web.findElement(By.name("q")).sendKeys("Gmail Login");
       Thread.sleep(2000);
       web.findElement(By.xpath("//div[@class='sbl1']")).click();

       web.findElement(By.xpath("//h3[@class='LC20lb']")).click();
       web.findElement(By.linkText("Sign in")).click();
       Thread.sleep(2000);
       web.findElement(By.xpath("//input[@type='email']")).sendKeys("xyz@gmail.com");
       web.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
       web.findElement(By.cssSelector(".A3sRAb.YKooDc .zHQkBf, .A3sRAb.YKooDc .MQL3Ob")).sendKeys("*****@");
       Thread.sleep(2000);
       web.findElement(By.xpath("//span[contains(text(), 'Next')]")).click();

   }

I am using Chromedrive 74 and selenium : 3.9.0 release 我正在使用Chromedrive 74和Selenium:3.9.0版本

I figured out the solution by myself . 我自己想办法。 just though may be it will help someone in future. 尽管这可能会在将来对某人有所帮助。 okay the problem was 好吧,问题是

   <a href="SIGN IN Page" target="_blank">

Because when new tab opens , Webdriver needs to shift control from old tab to new tab . 因为当新选项卡打开时,Webdriver需要将控制权从旧选项卡转移到新选项卡。 like this : 像这样 :

   WebElement link =   web.findElement(By.linkText("Sign in"));
   String l = link.getAttribute("href");
   web.get(l);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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