0

I have a question that I try to resolve. I have a screen in my webpage, that open a dialog box to upload a file. I managed to select the file, However the dialog box not closed, and stayed open. So I can not proceed with the other things on screen. I want to close the dialog box. I try to close the driver and it is closed the web page. I try to create a function of all the windows opened and it is not find the dialog box. How can I close this dialog box? this is what I done that not worked since it is not recognized the dialog box. (says only one window is opened) The problem is that in the devtool I do not find the locator that closed this dialog box, since I can not inspect it, can someone advise just how to close this? since the browser is stuck,

 Thread.sleep(8000); Set <String> w = deiver2.getWindowHandles(); // create set of all windows deiver2.switchTo() .activeElement(); System.out.println("Window title: "+ deiver2.getTitle()); deiver2.findElement(By.xpath("//input[@type='file']")) .sendKeys( "X:\\AutomationFiles\\yoyoy.pdf"); for (String h: w){ deiver2.switchTo().window(h); String s= deiver2.getTitle(); System.out.println("Window title: "+ deiver2.getTitle()); if(s.equalsIgnoreCase("Open")){ System.out.println("Window title to be closed: "+ deiver2.getTitle()); deiver2.close(); } } deiver2.switchTo().window(base); System.out.println("END"); 

enter image description here

enter image description here

    2 Answers 2

    0

    This most likely is a separate browser window and has it's own dev tools. To validate that, you can focus it and press F12 for the dev console. I see that you already getting the window handle. Put a debugger and try to do that thing with the dev tools. You will get the selector with which you can play around in the dev tools while you are under breakpoint

    3
    • No, not opened a dev tool to the dialog box. since it is box that display my computer, this is not a web page, prsss F12 not working, no dev tool to this box
      – Bastian
      CommentedJan 15, 2021 at 19:59
    • More over the window handle not see it as a window, it says only one window exists, I need a way to close this dialog box
      – Bastian
      CommentedJan 15, 2021 at 20:01
    • Hmm.. It won't work with Selenium then. You can trick it maybe like that. There should be an input box somewhere hidden. Take a look at this article it may help you. Otherwise it will be good if you can provide some running sample where I can try to help you :) dev.to/razgandeanu/how-to-upload-files-with-selenium-3gj3
      – A.Sideris
      CommentedJan 15, 2021 at 21:40
    0

    the solution I found is just not to open the select file dialog. I saw that if I just sent keys to the input without clicking the upload file button, that open the dialog box is working

     public void uploadFile() throws Exception { WebDriver deiver2 = getWebDriver(); Thread.sleep(3000); deiver2.switchTo() .activeElement(); deiver2.findElement(By.xpath("//input[@type='file']")) .sendKeys( "X:\\AutomationFiles\\yyyyyy.pdf"); System.out.println("END"); } 

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.