Error message for invalid calling page when using the selenium + chrome.fileSystem.chooseEntry function

I am currently developing a Selenium script to automate testing of a Chrome app that relies on the Chrome.fileSystem.chooseEntry API for selecting a directory. Interestingly, manual selection using this API works perfectly fine. However, when I attempt to do the same operation within my Selenium script, an error is thrown:

Unchecked runtime.lastError while running fileSystem.chooseEntry: Invalid calling page. This function can't be called from a background page.

Has anyone encountered similar issues with Selenium and chooseEntry integration, and if so, how did you resolve them?

Despite updating to the latest Chromedriver and exploring potential solutions like ChromeOptions, I have yet to find a resolution. I've noticed a lack of information online regarding using Selenium in conjunction with chooseEntry, adding to the complexity of solving this problem. For context, I am working with Chrome version 51.

At this point, I'm considering implementing a custom javascript entry point to manage path values during testing instead of relying on chooseEntry. However, I would prefer avoiding divergent code paths exclusively for testing purposes. If anyone has a more streamlined approach, please share your insights.

To provide further context based on a request, I am sharing the snippet of code causing the issue:

chrome.fileSystem.chooseEntry({type:'openDirectory'},function(entry) {
  chrome.fileSystem.getWritableEntry(entry,function(writeable_entry) {
      console.log("got writeable entry");
  });
 }, function(e) { errorHandler(e); });

Update: I have decided to implement a workaround by introducing a special javascript entry point. In essence, outside of Selenium automation, I manually execute code invoking chooseEntry and utilize the retainEntry API to retrieve the entry id. Subsequently, I redefine my codebase to reference this entry object rather than triggering chooseEntry afresh. Additionally, I have adjusted my Selenium script to invoke the restoreEntry entry point ahead of continuing script execution.

While this solution introduces discrepancies between test code execution and standard operational flow, it enables me to effectively run Selenium scripts. Nonetheless, if anyone can propose a more elegant resolution, I welcome your suggestions.

Correction: Following feedback from @Xan, I have amended my terminology from "extension" to "Chrome App."

Answer №1

One unconventional solution I've found is a rather crude hack. In order to navigate and select 'favorite' folders for Chrome Apps on OSX, I created a folder named favorites and utilized Robot keyPress commands. While not ideal, it does simulate a legitimate human interaction with the file interface.

private void selectOSXFolderFavorite(int favorite) {

    // Initiating Shift-Tab to access favorites list in an open OSX file folder dialog
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_SHIFT);

    // Scrolling to the top of the favorites list
    int i = 40;
    while (i-- > 0) {
        robot.keyPress(KeyEvent.VK_UP);
        robot.keyRelease(KeyEvent.VK_UP);
    }
    while (favorite-- > 0) {
        robot.keyPress(KeyEvent.VK_DOWN);
        robot.keyRelease(KeyEvent.VK_DOWN);
    }

    // Triggering an enter key press to select the designated folder
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
}

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

Trigger file download with ajax and php

I have been using an image picker plugin to select an image and then force it to download. Initially, I hard coded the PHP which worked perfectly fine. The download pop-up appeared and I was able to view the file without any issues. However, when trying to ...

How can I display JSON data as key-value pairs in ReactJS?

Transitioning from JavaScript to React, I've come across some threads that touch on this topic but none quite hit the mark. I have a local JSON file that was created with a Python script, and it looks something like this: [{"hello": 10, "world": 15 ...

Troubleshooting and Fixing AJAX Calls

When working with Asynchronous JavaScript, it is common to encounter issues where we are unsure of the posted request and received response. Is there a simple method for debugging AJAX requests? ...

Encountering an error stating that 'coordinates should consist of an array with two or more positions'

Utilizing turf.js to generate a line depicting the path of an individual while their location is tracked. An array of coordinate arrays resembling Turf.js (lineString) is causing this error: Uncaught Error: coordinates must be an array of two or more posi ...

Issue with JQuery .fadeToggle() function: Unexpected behavior causing automatic fade-out

$(document).on('click', '.tree label', function(e) { $(this).next('ul').fadeToggle(); e.stopPropagation(); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <ul cl ...

When jQuery inserts JavaScript into the DOM, it does not automatically execute the code

UPDATE: I initially used filter(), which was incorrect. I have since switched to find(), but unfortunately the issue persists. This snippet of code functions properly for me: $('#content') .replaceWith($( '<div> <d ...

Executing functions in AJAX using JavaScript callbacks

I'm in need of assistance to grasp how to start working on this problem. I have a task to write code for an object that allows multiple functions to be registered to execute a single common callback function. The objective of the object is to run al ...

implement CSS styles within a JavaScript function

I am trying to change the background every second with the following code, but I am having trouble including CSS properties like centering, covering, and positioning the image properly. How can I modify this function to incorporate these settings for the ...

CoffeeScript equivalent of when the document is loaded

Recently, I've been delving into Coffeescript for my web application, but I'm encountering a frustrating issue. The methods are not being called until I manually reload the page. I suspect that the missing piece may be the $(document).ready(func ...

Tips on eliminating the 'first', 'previous', 'next', and 'last' buttons in the twbs pagination plugin

I am searching for a straightforward pagination solution that only displays page numbers without control buttons like "first," "previous," "next," and "last." I have looked through the options available in twbs-pagination's github documentation and on ...

Loading 500,000 entries individually into mongodb results in a memory overflow

I am currently working on inserting a large volume of 500,000 records into a MongoDB collection. These records are stored in a CSV format, parsed, and then saved to an array. I am using a recursive function to insert the records one by one, and when a reco ...

What advantages does the use of $(e).attr(name,value) offer compared to using e.setAttribute(name,value)?

Scenario: The variable "e" represents an element of type "HtmlElement" and not a "css selector" I am referring to any attribute, not just the standard allowed ones like "atom-type" or "data-atom-type". Regardless of the attribute name, will it function wi ...

Using Google Maps to trace a line showing the distance traveled

I want to create a 'distance traveled' polyline along a set route using V3 of the Google Maps API. The polyline should pass through multiple waypoints/legs. Currently, I am using the DirectionsService to draw the entire route. In addition, I a ...

How to hide functions in Angular source code

Here's a common query. Typically, the code we develop in Angular gets compiled into a bundle file that is then sent to the browser, correct? The JavaScript code we write can be easily seen as is in the bundle file when viewing the source. How can we ...

What is the process for rendering components in a simulated DOM environment using enzyme?

I am working with a components library and have an interesting challenge. I have created a Tooltip component that renders a tooltip div at the very bottom of the document's body. Now, I want to test whether this div element appears after hovering over ...

Looking for an element that includes "== $0" right after the closing tag in HTML can be done using Xpath, CSS, or any other locators in Selenium with Python

a link to an image <div class=""><div>Mumbai, Maharashtra</div></div> Take a look at the above example for guidance. I attempted to use the code below but it failed to produce results: driver.find_element(By.XPATH,'//di ...

The Element Ui component fails to update when the prop of the Vue component changes

In my project, I have a parent component and several child components which all make use of the same prop. This prop is an array of keys that are used for a dropdown menu in element.js. Initially, when the children render for the first time, they do not co ...

Encountering a TypeError indicating that the asterisk is not functioning as a proper function

Whenever I run my server.js file, an error keeps popping up: TypeError: routing is not a function This occurs in the following line of code: routing(app); In my routing.js file, the content looks like this: // JavaScript source code var friends = requ ...

XPath expression containing calendar day is not valid

I attempted to use Selenium to select a date from a calendar using an XPath expression. I am quite sure the XPath is correct, but something seems to be off. https://i.sstatic.net/StrGI.png cal_day = ['1'] for day in cal_day: expression = f" ...

Using Typescript: How to pass a function as an argument in another function

In my angular application, I am working on the following setup: this.myServiceOne.getDataOne().subscribe((res => {this.variableOne= res})); this.myServiceTwo.getDataTwo().subscribe((res => {this.variableTwo= res})); this.myServiceThree.getDataThree( ...