我尝试使用 selenium 和 java 通过 google 应用程序自动注册。它的注册,但我在控制台中收到一些错误
I try to automate signup through the google application using selenium and java. its signup but I getting some error in the console
我是 selenium 自动化测试的初学者。我尝试通过 google 应用程序自动注册,注册后它会重定向到 deshboard,但我在控制台中遇到了一些错误。
driver.findElement(By.cssSelector("a.btn.btn-circle.btn-sm.btn-google.mr-2")).click();
WebDriverWait wait = new WebDriverWait(driver,50);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> s1 = driver.getWindowHandles();
Iterator<String> i1 = s1.iterator();
while(i1.hasNext())
{
String next_tab = i1.next();
if (!parentWindow.equalsIgnoreCase(next_tab))
{
driver.switchTo().window(next_tab);
WebDriverWait wait2 = new WebDriverWait(driver, 20);
wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("netcse02@gmail.com");
driver.findElement(By.id("identifierNext")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("*******");
driver.findElement(By.id("passwordNext")).click();
wait.until(ExpectedConditions.titleContains("Unify | Dashboard"));
System.out.println(driver.getTitle());
Thread.sleep(5000);
}
}
注册 google 申请:
没有这样的 window:window 已经关闭:
这是我在自动化框架中使用的两种通用方法。
public void waitForNewWindowAndSwitchToIt(WebDriver driver) {
String cHandle = driver.getWindowHandle();
String newWindowHandle = null;
Set<String> allWindowHandles = driver.getWindowHandles();
// Wait for 20 seconds for the new window and throw exception if not found
for (int i = 0; i < 20; i++) {
if (allWindowHandles.size() > 1) {
for (String allHandlers : allWindowHandles) {
if (!allHandlers.equals(cHandle))
newWindowHandle = allHandlers;
}
driver.switchTo().window(newWindowHandle);
break;
} else {
}
}
if (cHandle == newWindowHandle) {
throw new RuntimeException("Time out - No window found");
}
}
public boolean closeAllOtherWindows(WebDriver driver, String openWindowHandle) {
Set<String> allWindowHandles = driver.getWindowHandles();
for (String currentWindowHandle : allWindowHandles) {
if (!currentWindowHandle.equals(openWindowHandle)) {
driver.switchTo().window(currentWindowHandle);
driver.close();
}
}
driver.switchTo().window(openWindowHandle);
if (driver.getWindowHandles().size() == 1)
return true;
else
return false;
}
我是 selenium 自动化测试的初学者。我尝试通过 google 应用程序自动注册,注册后它会重定向到 deshboard,但我在控制台中遇到了一些错误。
driver.findElement(By.cssSelector("a.btn.btn-circle.btn-sm.btn-google.mr-2")).click();
WebDriverWait wait = new WebDriverWait(driver,50);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> s1 = driver.getWindowHandles();
Iterator<String> i1 = s1.iterator();
while(i1.hasNext())
{
String next_tab = i1.next();
if (!parentWindow.equalsIgnoreCase(next_tab))
{
driver.switchTo().window(next_tab);
WebDriverWait wait2 = new WebDriverWait(driver, 20);
wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("netcse02@gmail.com");
driver.findElement(By.id("identifierNext")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("*******");
driver.findElement(By.id("passwordNext")).click();
wait.until(ExpectedConditions.titleContains("Unify | Dashboard"));
System.out.println(driver.getTitle());
Thread.sleep(5000);
}
}
注册 google 申请:
没有这样的 window:window 已经关闭:
这是我在自动化框架中使用的两种通用方法。
public void waitForNewWindowAndSwitchToIt(WebDriver driver) {
String cHandle = driver.getWindowHandle();
String newWindowHandle = null;
Set<String> allWindowHandles = driver.getWindowHandles();
// Wait for 20 seconds for the new window and throw exception if not found
for (int i = 0; i < 20; i++) {
if (allWindowHandles.size() > 1) {
for (String allHandlers : allWindowHandles) {
if (!allHandlers.equals(cHandle))
newWindowHandle = allHandlers;
}
driver.switchTo().window(newWindowHandle);
break;
} else {
}
}
if (cHandle == newWindowHandle) {
throw new RuntimeException("Time out - No window found");
}
}
public boolean closeAllOtherWindows(WebDriver driver, String openWindowHandle) {
Set<String> allWindowHandles = driver.getWindowHandles();
for (String currentWindowHandle : allWindowHandles) {
if (!currentWindowHandle.equals(openWindowHandle)) {
driver.switchTo().window(currentWindowHandle);
driver.close();
}
}
driver.switchTo().window(openWindowHandle);
if (driver.getWindowHandles().size() == 1)
return true;
else
return false;
}