Utilize clipboard functionality in automated tests while using Selenium WebDriver in conjunction with JavaScript

How can I allow clipboard permission popups in automated tests using Selenium web driver, Javascript, and grunt?

https://i.stack.imgur.com/rvIag.png

The --enable-clipboard and --enable-clipboard-features arguments in the code below do not seem to have any effect.

import { Builder, Capabilities } from 'selenium-webdriver';

const chromeOptions = {
  // args: ['--enable-clipboard']
  args: ['--enable-clipboard-features']
};

const driver = await new Builder()
  .withCapabilities(Capabilities.chrome())
  .setChromeOptions(chromeOptions)
  .build();

The following code snippet is also unsuccessful:

 capabilities: {
    'browserName': 'chrome',
    'chromeOptions': { 'desiredCapabilities/goog:chromeOptions/prefs/profile.content_settings.exceptions.clipboard', {
            '[*.],*': { last_modified: '1576491240619', setting: 1 },
        }
      }
    }
  }

Answer №1

Before proceeding, ensure that you are not in incognito mode as clipboard permission cannot be granted while in this mode.

Next, it is important to open a URL before attempting to enable clipboard permission.

In Chrome, Selenium provides a specialized endpoint setPermission() for enabling clipboard (and other) permissions. Below is the code snippet to enable clipboard permission:

await driver.setPermission('clipboard-read', 'granted');
await driver.setPermission('clipboard-write', 'granted');

You can encapsulate this code within a function and call it after opening a URL to grant clipboard permission for that specific site.

If your linter tool (such as tslint) flags an error regarding the non-existent setPermission() method, you can disregard it by including the following line before the setPermission() line:

// @ts-ignore

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

Is React capable of storing and recognizing images within its system?

As a junior developer, I find this aspect confusing. Specifically, does reusing the same image on multiple routes in React result in the user downloading it more than once in the browser? I am striving to understand whether using the same image repeatedly ...

Production environment experiencing issues with Stripe functionality due to element remaining mounted

When making a payment in development mode, everything goes smoothly. However, when I switch to production, I encounter the following error message: v3:1 Uncaught (in promise) IntegrationError: We could not retrieve data from the specified Element. Please e ...

What is the best way to format a date input field so that when a user enters a year (yyyy), a hyphen (-

Need help with date formatting in the format yyyy-mm-dd. Seeking a way to prompt user input for the year and automatically append "-" to the date as needed. Also utilizing a datepicker tool for selecting dates. ...

What could be causing my completed torrents to sometimes not be saved to my disk?

Currently, I am working on developing a small torrent client using electron and webtorrent. Although everything appears to be functioning correctly initially, there is an issue where sometimes the resulting files from a finished download are not being save ...

When incorporating "<" or ">" into a parameter value in Angular Translate and then showcasing it in a textarea with ng-model

In my Angular Translate string, I am using a parameter that can be in the form of <test>. However, when this translate is displayed in a textarea, it shows up as &lt;test&gt; instead of <test>. Is there a way to ensure it appears correc ...

Change the identifier of a value within the React state

I am currently working on a form that includes input fields for both keys and values. The goal is to allow users to edit key value pairs, where editing the value field is straightforward, but editing the key field requires updating, removing, and tracking ...

How can CORS be activated? Is it through the server or Javascript, and where does this

Currently, I am testing my ReactJS website on localhost:3333 and my ASP.NET Web API 2 on localhost:54690. I am utilizing axios for my AJAX requests, but encountering an error when making a request. XMLHttpRequest cannot load http://localhost:54690/api/ ...

Can you please provide guidance on how to locate elements using XPath in selenium when they have multiple classes?

I am looking to extract the job titles from an Upwork job search that are contained within a specific HTML tag structure: <h4 data-job-title="::$ctrl.job" class="job-title m-xs-top-bottom p-sm-right ng-isolate-scope"> <a data-n ...

Breaking down arrays in Typescript

Let's say I have an array like this: public taskListCustom: any=[ {title: 'Task 1', status: 'done'}, {title: 'Task 2', status: 'done'}, {title: 'Task 3', status: 'done'}, {title: 'Task ...

What is the best way to change an http call in a controller to a Service/factory pattern that accepts a parameter?

Currently, I have a controller making use of http.get, http.push and http.post methods within my AngularJS app. During my learning journey with AngularJS, I've discovered that it's more efficient to place http.get calls in service files. While I ...

Creating a seamless vertical marquee of several images that continuously scroll from bottom to top without interruption can be achieved by following these

Currently, I am seeking to design a mobile-friendly HTML page that features a border with multiple color images moving smoothly from bottom to top on both the right and left sides of the mobile screen. The transition should be seamless without any gaps o ...

Executing actions on events in a Basic jQuery sliderLearn how to handle events and execute

I utilized the slider from the bjqs plugin at after reviewing the documentation, I noticed it only offers options and lacks events/functions. I am referring to events/functions like onSlideChange and onSlideDisplay. While other plugins such as bxslid ...

What is the process for incorporating Angular.js with a live messaging platform such as Pusher or PubNub?

Can Pusher or PubNub be implemented as an Angular service? Anyone have any examples of code for this kind of integration? ...

Updating an object with AngularJS

Let's consider the code snippet below: var absenceType = {name: 'hello'}; this.newAbsenceType = angular.copy(absenceType); After making changes to this.newAbsenceType, you want to apply these changes to the original object. I have explore ...

Convert an AJAX JSON object into values for multiple text boxes

When making an ajax call, I receive the following JSON input: var json = { "id_u":"1", "nombre_usuario":"JESUS", "apellido_paterno_usuario":"DIAZ", } I have text inputs that correspond to each key in the JSON object: <input type="text" name="id ...

Looking to transition from Node.js version v4.4.5 to v6.11.0 on your Windows system?

npm cache clean npm update -g I attempted upgrading using the provided commands, but unfortunately, the update did not go through as expected. Seeking advice for a successful update process. (Currently on Node.js 4.4.5 and aiming to upgrade to Node.js 6. ...

Preventing click event from bubbling up the DOM: Using Vue's @click

How can I access the child elements within a parent component? <div v-on:click.stop.prevent="onClickTemplateHandler"> <div> <h3 style="">Title</h3> <p>{{ lorem }}</p> </div> ...

Encountering an issue with html2canvas: receiving an error message stating "object

To print the div using Javascript, I encountered an issue with the generated barcode not appearing in the printed page. This led me to use the html2canvas approach to 'render' the div before printing it out. Here is the code snippet: HTML: < ...

Error encountered: In a headless browser on Ubuntu using Python, the element is not visible when attempting to invoke the send_keys method

I'm experiencing issues with the send_keys method. options = webdriver.ChromeOptions() options.add_argument('headless') driver = webdriver.Chrome(executable_path= '/home/ec2-user/chromedriver', chrome_options=options) base_url = " ...

I will evaluate two arrays of objects based on two distinct keys and then create a nested object that includes both parent and child elements

I'm currently facing an issue with comparing 2 arrays of objects and I couldn't find a suitable method in the lodash documentation. The challenge lies in comparing objects using different keys. private parentArray: {}[] = [ { Id: 1, Name: &ap ...