Testing the data URLs of cookies in Selenium using JavaScript

Currently, I have a Behat test that runs Selenium whenever Javascript is required. The test works perfectly fine if Javascript is disabled.

However, the error feedback I receive from Selenium is the following:

unknown: Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs.
        (Session info: chrome=48.0.2564.109)
        (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 4.2.0-16-generic x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 7 milliseconds
      Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
      System info: host: 'ca7a41afbfee', ip: '172.17.0.10', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-16-generic', java.version: '1.8.0_45-internal'
      Driver info: org.openqa.selenium.chrome.ChromeDriver
      Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/tmp/.com.google.Chrome.WWmJvH}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=48.0.2564.109, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
      Session ID: b8a3f435fe337ca77d523d5b72f6235b (WebDriver\Exception\UnknownError)

I am unsure of what I am doing wrong here. I have read some posts mentioning cookies, but I am not certain where I should include them.

Answer №1

To successfully set a cookie with the Chrome driver, ensure that the page is completely loaded before attempting. Employ Selenium to wait for the page to finish loading before setting cookies.

Answer №2

Make sure to open the page before adding a cookie:

$capabilities = DesiredCapabilities::firefox();
$host = 'http://localhost:4444/wd/hub'; // default
$this->webDriver = RemoteWebDriver::create($host, $capabilities, 5000);
$this->open('/');
$cookie = array();
$cookie['name'] = 'COOKIE_NAME';
$cookie['value'] = 'COOKIE_VALUE';
$this->webDriver->manage()->addCookie($cookie);

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

Managing the re-triggering of a function within useEffect upon the user clicking the "Back Button" in a React application

Is there a way to prevent the loadUserPosts() function from being called again when the user clicks the 'back button' on their browser? It seems like the isLogged useState is being changed when the back button is clicked. The loadUserPosts funct ...

AJAX request lacks the 'access-control-allow-origin' header

I'm currently integrating a weather API into my app to display real-time weather information. Although I've used this API before, I am now attempting to fetch the data asynchronously using AJAX to avoid full page reloads. Below is the JavaScrip ...

Error encountered while trying to call callback functions

I encountered an error in my code, but I managed to resolve it independently. Could someone please provide an explanation of why the code wasn't working and delve into the mechanics behind the issue? Here is the code snippet: var listTables = functi ...

Issue with navigation links on HTML website not functioning as expected

I would like the dropdown menu items to be clickable. For example: Menu item: Services Sub items: - branding } These already have working links - marketing } However, when I try to replace '#' with a link for Services, it d ...

Set onfocus for DOM elements dynamically

I have a question regarding assigning onfocus or similar functions to DOM elements during runtime. Here is the scenario: <input type="text" id="box" onfocus="inputFocused()"/> Now, in a runtime assignment case: <input type="text" id="box"/> ...

Customize the appearance of the "Collapse" component in the antd react library by overriding the default styles

Incorporating JSX syntax with *.css for my react component. Displayed below is the jsx code for the antd collapse section. <Collapse defaultActiveKey={["1"]} expandIconPosition="right" > <Panel header="This is p ...

Python and Selenium scraping activity encountered captcha blocking on a website protected by DataDome security measures

I have been working on scraping car data from various websites using Selenium with Chrome browser. However, I've run into issues where some websites block Selenium with captcha validation after just 1 or 2 requests. One example of this is . I attempte ...

Issue with click event not triggering initial interaction with dynamically inserted elements through AJAX requests

I am experiencing an issue with my ul element that is being populated with li elements through AJAX. When I try to click on these li elements, something peculiar happens. The functionality only works when I click for the second time, not the first. Despit ...

One efficient way to handle multiple concurrent tasks in NodeJs is by using the forEach method to iterate

Having trouble getting the promises to return any values, as they are coming back empty. Despite following suggestions on Stack Overflow, I am still unable to resolve this issue. Frustration levels are high and I'm feeling lost; Can anyone help me pi ...

The dimensions of the body are set to 100vh in height and width. However, the div inside this body has a width of either 100vh or 100%, but it is not

I am trying to create a div element that has a width equal to the viewport of the browser. However, I am encountering issues when applying the CSS property width:100vh to the body element. Here is my code snippet: body { font-family: Staatliches; fo ...

Utilizing CSS and JQUERY for Styling Border radius

Is there a way in jQuery to select specific parts and apply a "border radius"? I've been struggling to use a jQuery selector to achieve this. Is there another method using CSS? I don't want to manually add a "CLASS" to the HTML code to solve th ...

Is it possible for me to perform cross-site scripting using JavaScript within my personal browser, specifically Firefox?

While watching a Video Tutorial on a certain website, I noticed that the videos were hosted on platform.thinkific.com and displayed in a light theme. However, I prefer Dark Theme, so I decided to invert the color of the video using the filter: invert(90%) ...

Gauging Screen Size: A Comparison between Media Queries and JavaScript for Adjusting Div Position

I am currently facing an issue with the banner on my website. It contains a slider and has a position set to absolute. The problem arises when viewing it on smaller screens, as only the left side of the wide banner is visible. Initially, I tried using med ...

Using asynchronous functions in React Native still generates a promise despite the presence of the 'await' keyword

After making an API call, my react-native component is supposed to return some SVG. Despite using an async function with await, the function still returns a promise that has not resolved yet. I have seen similar questions asked before, but I am puzzled as ...

What is the best way to verify if an Android permission request has been successfully granted or denied

I've been working on my RN application and encountered the following code snippet. import { PermissionsAndroid } from 'react-native'; export default new Promise(() => { return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS ...

Ways to dynamically update a div with data from a JSON response

I'm currently in the process of developing a search platform. I have three static divs on the search results page that display certain content, all containing similar code. For example: <div id="result" class="card"> <img src="hello.png" ...

Ways to resolve the issue with the Argument of type 'Date[]' not matching the parameter type '(prevState: undefined) in React

I've encountered an issue while trying to construct my project. The error message reads as follows: Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) Here's the excerpt of the code in questio ...

Switch between two distinct menus (Reactjs + Material UI)

Recently, I designed a robust menu system that includes a Switcher feature. The concept is straightforward - if the switch is turned off, display the 1st menu; and if it's on, show the second menu. However, there seems to be an issue. When the switch ...

In search of a React.js/Redux OpenID library or example, particularly focused on Steam OpenID integration

Currently, I am developing a Node/Express REST + React/Redux application that requires Steam OpenID for authentication. Despite searching extensively for tutorials, libraries, or example code related to Steam OpenID (or any other OpenID), I have come up em ...

Utilize ES6 in React to dynamically update state with setState and retrieve state with the

Recently I discovered a technique for handling multiple input events using dynamic state. If I have a state setup like this this.state = { name_1: 'john', name_2: 'james' } I can access my state values like this [1,2].forEach ...