Unable to close the file upload window using Selenium

I've encountered a dilemma that I'm trying to solve. On my webpage, there's a screen that opens a dialog box for file upload. Although I managed to select the file, the dialog box refuses to close and remains open, preventing me from proceeding with other tasks on the screen. I attempted various methods like closing the driver, creating a function to find all open windows, but none of them could locate the pesky dialog box. How can I successfully close this persistent dialog box? The code snippet below showcases my unsuccessful attempt in which it recognizes only one window is open.

 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");

https://i.sstatic.net/TBDOw.png

https://i.sstatic.net/TBDOw.png

Answer №1

It appears that this is likely a standalone browser window with its own set of development tools. To confirm this, simply bring it into focus and use the shortcut F12 to access the dev console. I notice you already have the window handle. Insert a debugger and experiment with the dev tools in order to identify the selector for further exploration while debugging

Answer №2

In order to avoid opening the select file dialog, I discovered that simply sending keys to the input without clicking the upload file button still triggers the dialog box to open.

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

    System.out.println("Process Complete");

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Header Blocks that are Fixed While Scrolling in fullPage.js Sections Using the "scrollOverflow: true" Feature

I am experiencing an issue where a fixed header on my website prevents scrolling through sections when hovering, specifically when the setting scrollOverflow: true is enabled. However, everything works fine and scrolling through all sections is possible w ...

Why does my anchor disappear after a second when clicked to show the image?

Hi everyone, I'm having an issue with a dropdown menu that I created using ul and anchor tags. When I click on one of the options, an image is supposed to appear. However, the problem is that the image shows up for just a second and then disappears. I ...

What is the best way to choose an Iframe using Selenium?

I am trying to locate and retrieve data from an iframe with the id "iframe00237": Here is the HTML code: <iframe src="http://example/iframe/v2.html?id=5225dddd-588a-49c2-961e-e3417cf5a728 scrolling="no" frameborder="0" marginwidth="0" marginheight="0" ...

Exploring the Power of Modules in NestJS

Having trouble with this error - anyone know why? [Nest] 556 - 2020-06-10 18:52:55 [ExceptionHandler] Nest can't resolve dependencies of the JwtService (?). Check that JWT_MODULE_OPTIONS at index [0] is available in the JwtModule context. Possib ...

Traverse a nested array containing children elements to construct a pathway map

I am currently working with a multidimensional array that contains children (subcategories): As I am setting up Angular routing, I receive this data format from an API. const items = [{ displayName: 'News', urlName: 'news', subca ...

Setting a default value in ng-options can be accomplished by using the ng-init

One way to set a dropdown list with a default value in AngularJS is by using the following code: <select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init="repeatSelect = data[0].id"> <option ng-repeat="option in data" val ...

Dealing with Typing Errors in Angular with Typescript: Error message 'x' is not a function

I'm facing an issue in my schedule.component.html where I am trying to create a button and link its click event with a function defined in the associated schedule.component.ts file. The button is coded like this: <button type="submit" ...

recursive algorithm utilizing an array as an argument

Currently, I am in the process of developing a function that extracts chest exercises from an array titled "chest". This particular function is required to randomly select multiple exercises, achieved by utilizing a random pointer. In order to avoid selec ...

Having trouble locating the Selenium element on the webpage?

I am encountering an issue with Selenium during a click event WebElement btn = driver.findElement(By.xpath("//form[@name=\"addMemberForm\"]/div[14]/div/button")); System.out.print(btn); The output of the print statement [[ChromeDriver: chro ...

Remove the "href" from Zend2 navigation functionality

When using Zend2 navigation from an array passed in Zend\Navigation\Navigation, everything works smoothly if child items are opened on parent item mouse hover. However, undesirable actions occur when they are opened on mouse click, as the user is ...

Setting up xvfb on a Linux machine

Attempting to automate browsing on a Linux application server using Selenium is proving to be challenging. The issue arises when my 'perl recording' triggers a request to start the browser, resulting in the standalone selenium server throwing an ...

What is the best way to incorporate the ability to strikethrough items in my task list?

I am currently working on a project to create a dynamic To-Do-List using Express and EJS. My goal is to implement a feature in the To-Do-List where checking a checkbox will cause the corresponding content to be striked-through. Initially, my approach invo ...

Is there a way for me to discover the top trending photos on Instagram today?

Finding information on the Instagram API can be quite challenging due to poor documentation. Is there a method available to discover the most liked Instagram photos by location, such as identifying the top picture liked by Danish users today? Any insight ...

A guide on Using Angular to Filter Data by Date Input

Trying to filter out specific notes created on a selected date. The date format in the db.json files is '2023-08-14' and should match the input format...values are compared in the filter function. The issue arises as nothing is added to the filt ...

Building a dynamic form in Angular 1.X that allows users to adjust values with a button click

Utilizing Angular to create a user-friendly form where users can input values, with the option to use +/- buttons for easier navigation on tablets and other devices. I am still learning about Angular and facing some challenges in implementing this feature ...

refetchQueries may be effective for specific queries

Using a Friend component within my AllFriends screen triggers the following mutation: const [deleteUserRelation] = useDeleteUserRelationMutation({ onCompleted: () => { Alert.alert('Unfriended'); }, refetchQueries: [{ query: ...

activate a specific tab within a tab container using JavaScript

Having an issue with the JavaScript function below that I am using to set active ASP.NET tabs. Whenever I run the code, it always returns CurrentTab as "null". Can anyone help me solve this problem? function SetActiveTab2(tabNumber) { try { ...

Error in Node.js: Trying to access the 'body' property of an undefined variable

While working on a project for a Udacity course, I encountered a stumbling block. The issue revolves around capturing user input from a form and making a post request to return a javascript object. However, when attempting to run the server with node js, I ...

Comparison between websocket implementation in PHP and Node.js

I'm curious to learn about the distinctions between using "websocket php" and node.js for a chat feature. I currently have a chat implemented with websocket php, but I'm wondering if migrating it to node.js would be a better option. Any insights ...

Tips for arranging information in ng-repeat using nested objects within JSON data on AngularJS

Looking to display an array of object properties in an Angular view. Here is the object: $scope._Json = { "foo": { "ItemDimension1": { "Item": "item1", "ItemIndex": 1, "SelectedItems": [{ "C ...