I am trying to write selenium tests for a website using java. However, I have come across a problem when testing file uploading.
When I click the file upload button, it automatically opens the windows file upload. I have code working to put the file path ("D:\\test.txt") into selection. From researching this subject I understand there is no way for selenium webdriver to handle this. So my question is this: what is a way I can simply close the upload window in an automated way? Indeed the sendKeys working with selecting the txt file but the window upload still not closing.
Thanks in advance
ProductActionCode :
public static void AutoInsert_Execute(WebDriver driver) throws Exception {
ConfirmationPlaceBet_Page.btn_ChanShiOdd(driver).click();
ConfirmationPlaceBet_Page.btn_UploadOddTxt(driver).click();
ConfirmationPlaceBet_Page.btn_DocumentToBeUpload(driver).click();
ConfirmationPlaceBet_Page.pick_DocumentToBeUpload(driver).sendKeys("D:\\test.txt");
ConfirmationPlaceBet_Page.btn_ProceedUploadAuto(driver).click();
ConfirmationPlaceBet_Page.btn_ConfirmedUploadAuto(driver).click();
for (int i = 0; i < 3; i++) {
ConfirmationPlaceBet_Page.btn_AddDoubleBet(driver).click();
}
ConfirmationPlaceBet_Page.btn_ConfirmNumberToBet(driver).click();
for (int k = 0; k < 49; k++) {
ConfirmationPlaceBet_Page.btn_IncreaseBet(driver).click();
}
ConfirmationPlaceBet_Page.btn_ProceedBet(driver).click();
ConfirmationPlaceBet_Page.btn_ConfirmBet(driver).click();
}
ConfirmationPlaceBetCode :
public static WebElement pick_DocumentToBeUpload(WebDriver driver) throws Exception{
try{
driver.manage().timeouts().implicitlyWait(200, TimeUnit.SECONDS);
element = driver.findElement(By.name("file"));
Thread.sleep(500);
//Log.info("Pick Lottery1 ");
}catch (Exception e){
Log.error("Button is not found on the Confirmation Page");
throw(e);
}
return element;
}
HTML CODE :
<div id="filePicker" class="webuploader-container"><div class="webuploader-pick">选择文件</div><div id="rt_rt_1a24olu914nt122e1qls1c5l1b2qm" style="position: absolute; top: 0px; left: 0px; width: 86px; height: 30px; overflow: hidden; bottom: auto; right: auto;"><input type="file" name="file" class="webuploader-element-invisible" multiple="multiple" accept="text/*"><label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label></div></div>
ConfirmationPlaceBet_Page.pick_DocumentToBeUpload(driver).sendKeys("D:\\test.txt");it should close close window automatically.