I am trying to upload one document from my system to one application and it includes flow as:
Library page >> Upload document button >> Web-based select document pop-up >> after click on select file in pop-up, it open the system pop-up from where need to select file.
for above case, I have written code as:
WebElement element = driver.findElement(By.xpath("//button[@class='btn btn-primary upload-doc-btn cap-letter bold upload_document_image marginrightfix18']")); Actions action = new Actions(driver); action.moveToElement(element).click().perform();
WebDriverWait wait = new WebDriverWait(driver, 300);
WebElement selectElement = wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("//label[@class='btn btn-primary file-select-btn margintop10']")));
WebElement selectdoc = driver.findElement(By.xpath("//label[@class='btn btn-primary file-select-btn margintop10']"));
Actions actions = new Actions(driver);
actions.moveToElement(selectdoc);
actions.click();
// Up to this click working and getting the system window opened to me, but the given path of file using send keys not working and not able to upload the mentioned file
actions.sendKeys("C://Users//Vishnu//Documents//seleniumnotes.docx");
actions.build().perform();
For above code, I am getting "unknown error: cannot focus element" error due to the given file not getting selected to upload.
Please suggest your valuable answers. Good if get answer with .sendkeys() method.
I have tried the "Robot" class as well but that as well doe snot worked for me, so trying with .sendkeys().
Your answer can save my day!!