[英]Java Selenium can't login GMail
i am learning Selenium with java . 我正在用Java学习Selenium。 My use case is :
我的用例是:
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.