-1

I am new to browser automation and learning selenium. I have managed to set up jar dependencies and the driver dependency too. It is opening the webpage.., detecting the loading of the page and also detecting element is available to click. But it has opened a select file dialog box and i am unable to select file via selenium.

Here is my java code :

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");

WebDriver driver = new ChromeDriver(options);
driver.get("https://xyz.abc.pqr");

try 
{
    WebDriverWait wait = new WebDriverWait(driver, 60);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("element_id_1")));

    System.out.println("Loaded and in....");

    WebElement AttachMenu = driver.findElement(By.className("Class_1"));
    AttachMenu.click();
    System.out.println("Clicked Attach menu....");

    // <input type="file" accept="image/*,video/*" multiple="" style="display: none;">

    // As you can see above input element is not having any id or class

    // How do i sendkeys to above input element that has opened dialog

    // this is the question...

}
catch (TimeoutException e)
{
    System.out.println("Element not found...");
}

// driver.quit();

IT IS NOT UPLOAD IT IS JUST SELECTION OF FILE; I WILL CLICK ON UPLOAD BUTTON THEREAFTER...

Any help / inputs will be appreciated and thank you in advance for giving your valuable time over this question.

sandhya sasane
  • 1,334
  • 12
  • 19
  • 1
    U can paste this code befor dialog box `driver.switch_to_active_element()`and `driver.find_element_by_I'd(I'd of dailog close button).click()` – bhupathi turaga Jun 11 '18 at 15:23
  • @bhupathituraga, And how to load that dialog box with the absolute file path? Also will you please answer this question with some more details, so that it will be more clear to me – sandhya sasane Jun 11 '18 at 16:03
  • Possible duplicate of [How to handle windows file upload using Selenium WebDriver?](https://stackoverflow.com/questions/11256732/how-to-handle-windows-file-upload-using-selenium-webdriver) – JeffC Jun 11 '18 at 18:12
  • 1
    @JeffC, Please make habit of reading the question before down-voting, It is related to Apple Mac OSX and not for the WINDOWS..!! – sandhya sasane Jun 12 '18 at 04:43
  • If you click the upload button, you have to deal with the dialog. Follow the instructions in the link. – JeffC Jun 12 '18 at 04:57
  • @JeffC, Okay..., I am gonna follow the instructions and will update here.. Thank you – sandhya sasane Jun 12 '18 at 05:08
  • @JeffC, I am not able to click on
    this button as it has no class nor the id...!!
    – sandhya sasane Jun 12 '18 at 05:11
  • Keep the HTML snippet of that dialog box – bhupathi turaga Jun 12 '18 at 08:37
  • @bhupathituraga, this is the HTML that opening file select dialog.. and dialog boxes do not have html codes it is populated by system – sandhya sasane Jun 12 '18 at 10:21
  • 1
    If you read the info in the link, you aren't supposed to click the button. Read it carefully and try the code there. – JeffC Jun 12 '18 at 12:50
  • @JeffC, yes your link also helped me a lot. thanks it has been resolved now. – sandhya sasane Jun 12 '18 at 13:05

1 Answers1

0

There were two issues :

  1. How to click <div role="button" title="Attach"> button; which has no class and no id
  2. How to sendkeys to <input type="file" accept="image/*,video/*" multiple="" style="display: none;"> which also has no class and no id.

It has been solved after a lots of try and errors as ...

driver.findElement(By.xpath("//div[@title='Attach']")).click();
System.out.println("Attach clicked....");

WebElement MediaButton = driver.findElement(By.className("xyzmm"));
MediaButton.click();

System.out.println("Select clicked....");
WebElement uploadElement = driver.findElement(By.xpath("//input[@accept='image/*,video/*']"));

uploadElement.sendKeys("/Users/Apple/Desktop/logos/Team1.png");

Still uploadElement dialog is visible.. and how to execute javascript to make it display none is in question..., trying on it now... The question has been resolved

sandhya sasane
  • 1,334
  • 12
  • 19