I am using selenium webdriver and headless browser for running my script. I am trying to upload file for that element required to use is invisible in html source page. I tried making it visible by using javascript and I can able to make it visible and upload file but it is working on normal fire fox browser. But when I am executing same script on headless browser it is not working below is the html source and code I am using.
<input id="CASE_file_select" class="required" type="file" multiple="" size="25" name="CASE_file" style="display: none;"/>
Code which I am using
JavascriptExecutor executor = (JavascriptExecutor)oDriver;
executor.executeScript("document.getElementById('CASE_file_select').style.display='block';");
oGeneric.sleepTimer(5);
Utility.constant.objLogs.writeLog("After executing java script");
WebElement ofilepathxpath = oDriver.findElement(By.xpath("//input[@id='CASE_file_select']"));
oGeneric.sleepTimer(5);
Utility.constant.objLogs.writeLog("After finding xpath of Invisibleelement");
Utility.constant.objLogs.writeLog("After finding xpath of file");
try {
ofilepathxpath.sendKeys(sfilepath);
oGeneric.sleepTimer(8);
}catch (Exception e){
Utility.constant.objLogs.writeLog("Failed to choose file");
}
Utility.constant.objLogs.writeLog("After choosing file");
I am not sure javascript executor is working on headless browser I have to execute all my scripts on headless browser it is requirement of project. Please let me know solution for this.
Below is the code next to above where script fails
if(oDriver.findElement(By.xpath(".//*[@id='0_CASE_fileDiv']")).isDisplayed()){
Utility.constant.objLogs.writeLog("File selected succesfully");
}else{
Utility.constant.objLogs.writeLog("File not selected");
}
Utility.constant.objLogs.writeLog("After choosing case file");
String sBtnuploadCaseRelatedFilexpath = (String) constant.hashXPaths.get("btnUploadCaseRelatedFile");
WebElement oBtnuploadCaseRelatedFile = FindElement(oDriver,sBtnuploadCaseRelatedFilexpath);
Utility.constant.objLogs.writeLog("After finding xpath of upload btn ");
oBtnuploadCaseRelatedFile.click();
oGeneric.sleepTimer(10);
Utility.constant.objLogs.writeLog("After click on upload btn ");
scripts fails when it will go to if condition bcz upload btn is invisible bcz file is not selected.