ericmckean / chromedriver

Automatically exported from code.google.com/p/chromedriver
0 stars 0 forks source link

Switching between Windows #995

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
See http://goo.gl/ll2FvQ for common issues.

Issue Description:
Child window button click gives away control to main window

Steps to reproduce (if relevant, you MUST provide a simplified html page or
link to public site):
1. There is parent Chrome WIndow & Child Chrome window.
2. On click of button on child window, triggers an alert on Parent Window.
3. Then User is suppose to handle the alert on Parent window , which will close 
the both alert & Child window.
4, While trying to automate this,Please find code,

  For(String windowHandle:driver.getWindowHandles())
  {
     driver.switchTo.window(winHandle);
     if(driver.getTitle().equals("ChildWindowName"))
     {
       driver.findElement(By.xpath("buttonOnChildWindow")).click();
     }
  }
  driver.switchTo().window(ParentHandle);
  //HandleAlert
5. However, code is stuck at 
driver.findElement(By.xpath("buttonOnChildWindow")).click(); & not coming out 
from there.
6. I am using Chrome version 38.0.2125.111 ^ Selenium Server Jar version2.43.1

-----Other helpful tips:
Attach your chromedriver log with verbose logging enabled (see
http://goo.gl/5Sx8mC for how to do this).

Original issue reported on code.google.com by shweta....@gmail.com on 9 Dec 2014 at 3:08

GoogleCodeExporter commented 9 years ago
One more thing, having stuch at button click for longer time, then it throws 
exception, 
 chrome not reachable

Original comment by shweta....@gmail.com on 9 Dec 2014 at 3:10

GoogleCodeExporter commented 9 years ago
1. what version of chromedriver you use?
2. which OS you use?
3. can you provide complete test program + HTML

Original comment by andrewch...@chromium.org on 10 Dec 2014 at 7:47

GoogleCodeExporter commented 9 years ago
1. Version of chrome Driver 
   I am not sure if the one I am using is latest. I just randomly got it because I am not finding an appropriate link to download the Chrome Driver. All the link say its missing. But the ChromeDriver.exe has creation date stamped as 13/11/14
 http://code.google.com/p/chromedriver/wiki/WheredAllTheDownloadsGo?tm=2
Please let me know the link to download the latest Chromedriver.exe
2. I am using Windows 7
3. 

package com;
import java.io.File;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote..DesiredCapabilities;

public class test2 {

 public static final String fileSeparator = System.getProperty("file.separator");
 public static final String chromeDriverPath = "D:"+fileSeparator+"Reference Library"+fileSeparator+"ChromeDriver.exe";

 static WebDriver driver;
 public static void main(String args[]) throws InterruptedException
 {
  File file = new File(chromeDriverPath);
  System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
  DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
  capabilities.setJavascriptEnabled(true);
  capabilities.setCapability("requireWindowFocus", true);
  driver = new ChromeDriver(capabilities);

  driver.get("https://siteURL.com");
  driver.manage()..window().maximize();
  Thread.sleep(5000);
  driver.findElement(By.id("userId")).sendKeys("username");
  driver.findElement(By.id("password")).sendKeys("password");
  driver.findElement(By.id("loginBtn")).click();
  Thread..sleep(10000);

  WebElement element = driver.findElement(By.xpath("//*[@id='myGnb1']/div[2]/ul/li[4]/dl/dt/a"));
  JavascriptExecutor executor = (JavascriptExecutor)driver;
  executor.executeScript("arguments[0].click();", element);
  Thread.sleep(20000);
  driver.navigate().to("https://dev.siteURL.com/mill/BilEmail.action");
  Thread.sleep(20000);
  driver.findElement(By.xpath("//*[@id='aBillType2']")).click();
  driver.findElement(By.xpath("//*[@id='formBillAddr']/div[4]/p/a/img")).click();
  Thread.sleep(2000);
  String ParentHandle = driver.getWindowHandle();

  if(driver.getWindowHandles().size()==2)
  {
   for (String winHandle : driver.getWindowHandles())
   {
    driver.switchTo().window(winHandle);
    if(driver.getTitle().equals("ChildWindowTitle"))
    {  
     System.out.println("MMS specification window :"+driver.getTitle());
     driver.findElement(By.xpath("//*[@id='cfmOllehPopupWrapper']/div/div/div/div/a[1]/img")).click();
    }
   } //for

  }//if
  driver.switchTo().window(ParentHandle);
  System.out.println("Handle is with Parent Window");
  Alert alert = driver.switchTo().alert();
  System.out.println(alert.getText());
  alert.accept();

 }
}
This is the program I am trying out, 
Th program gets stuck at 
driver.findElement(By.xpath("//*[@id='cfmOllehPopupWrapper']/div/div/div/div/a[1
]/img")).click();

I can not post the HTML content due to security reasons. Please let me know if 
u need any more inputs.

Original comment by shweta....@gmail.com on 11 Dec 2014 at 1:22

GoogleCodeExporter commented 9 years ago
Regarding Chrome Driver , I have tried the execution with ChromeDriver 2.9 & 
2.12

Original comment by shweta....@gmail.com on 11 Dec 2014 at 2:16

GoogleCodeExporter commented 9 years ago
ok, let me look into it

Original comment by andrewch...@chromium.org on 11 Dec 2014 at 2:21

GoogleCodeExporter commented 9 years ago

Original comment by samu...@chromium.org on 21 Feb 2015 at 12:18

GoogleCodeExporter commented 9 years ago
Since your webpage is not available to reproduce the problem, We tried with the 
below code .And Issue is not reproducible

System.setProperty("webdriver.chrome.driver", 
"/usr/local/google/home/gmanikpure/Downloads/chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("requireWindowFocus", true);
driver = new ChromeDriver(capabilities);

driver.get("http://google.com");

// To show alert after 30secs of page loading
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("onload = setTimeout(function(){alert('Hello');}, 
30000);");

//To click Images link in new window
WebElement elem = driver.findElement(By.linkText("Images"));
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).click(elem).keyUp(Keys.CONTROL).build().perform();

driver.manage().window().maximize();
Thread.sleep(2000);

String ParentHandle = driver.getWindowHandle();

if(driver.getWindowHandles().size()==2)
{
for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);

} //for

}//if

Thread.sleep(35000);
// To switch to the parent window after the alert appears.
driver.switchTo().window(ParentHandle);
System.out.println("Handle is with Parent Window");
Alert alert = driver.switchTo().alert();
System.out.println(alert.getText());
alert.accept();

Configuration:-
A]
 Linux ubuntu
 Selenium version – 2.45
 Chromedriver version – 2.14
 Chrome browser version – 40.0.2214.115 (64-bit)
 Java – 7

[B]
Windows 8.1
Chromedriver 2.14
Selenium version – 2.44
Java 8
Chrome browser - 41.0.2272.64(64-bit)

Please let us know if it differs from what you are doing

Original comment by gmanikp...@chromium.org on 2 Mar 2015 at 7:42

GoogleCodeExporter commented 9 years ago

Original comment by andrewch...@chromium.org on 6 Mar 2015 at 8:35