I want to click on the Upload button but when the script runs this click event triggers a new browser to open which I cannot simulate when I try to test it manually.
I deliberately click on Start link (in the code) hoping that this new window opens only the first time and can be handled then and there, and thereafter I can concentrate on the click event of the Upload button in the parent window. But once again it brings up the new browser window.
How should I handle this?
driver.get("http://s000.tinyupload.com/index.php");
driver.manage().window().maximize();
driver.findElement(By.xpath("/html/body/table/tbody/tr[3]/td/div/table/tbody/tr/td[2]/span/a[1]/b")).click(); //Start link
Thread.sleep(4000);
Set<String> handles = driver.getWindowHandles();
String firstWindowHandle = driver.getWindowHandle();
handles.remove(firstWindowHandle);
String winHandle = handles.iterator().next();
if (winHandle != firstWindowHandle) {
String secondWindowHandle = winHandle;
driver.switchTo().window(secondWindowHandle);
driver.close();
driver.switchTo().window(firstWindowHandle);
}
driver.findElement(By.cssSelector("input[class=pole_plik]")).sendKeys(path);
driver.findElement(By.cssSelector("img[alt=Upload]")).click(); //upload button