question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using cy.get().click() not working on html button

See original GitHub issue

Current behavior:

I started from scratch by creating an html page with a button.

When I want to click on my button using the script cy.get("...").click() on my button. No action is taken and I receive the following error:

CypressError: Timed out retrying: this.ol_originalAddEventListener is not a function

I tried passing an xpath using the xpath plugin and I still have the same error.

Desired behavior:

Using the script cy.get("...").click() on my button must be work.

Steps to reproduce: (app code and test code)

Step 1: Create a project from scratch, following this project:

Here is my project : image

Here is the “buttons.html” source code:

<!DOCTYPE html>
<html>
<head>
<title>Titre du document</title>
</head>
<body>
<button id="test" onclick="window.location.href = 'https://fr.w3docs.com/';">Cliquez Ici</button>
</body>
</html>

The goal being to click on my button, I created a very simple test that allows me to click on this button. This is my source code:

/// <reference types="Cypress" />

context('Actions', () => {
beforeEach(() => {
cy.visit('./buttons.html')
})

it('test button html', () => {
cy.get('#test').click();

})
})

Despite this, I still have the same mistake below:

This is the log console:

image

Here is my package.json : image

{
"name": "testing-error",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cypress": "^3.7.0"
}
}

I use Chromium only to run my test.

The following files: the cypress.json, cypress/support directory and cypress/plugins directory are “empty” by default when installing cypress.

No CSS or others references my error function.

Versions

Cypress : 3.7.0 Chromium : 74.0.3729 OS : MacOS IDE : VSCode

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
edsrzfcommented, Feb 17, 2020

I finally figured out that my issue was related to the OneLogin Chrome extension. If I disable browser extensions when running with Chrome, it fixes the issue.

In cypress/plugins/index.js:

module.exports = on => {
  on('before:browser:launch', (browser = {}, launchOptions) => {
    if (browser.name === 'chrome') {
      launchOptions.args.push('--disable-extensions')

      return launchOptions
    }
  })
}

I believe Cypress should disable Chrome extensions by default, but honestly find the issue template for this repo very cumbersome, so I’m just leaving this here.

1reaction
jennifer-shehanecommented, Feb 18, 2020

@edsrzf Oof, thanks for the update.

Some people test their browser extensions in Cypress, so disabling them outright would not be the right approach unfortunately. Although, we may be able to detect in Cypress 4.0 if you are modifying the launchOptions.extensions and remove the --disable-extensions flag in this case.

This still leaves the cases where some people use extensions for development purposes though. So, they want the extensions in Chrome to work that help them in their devtools etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress does not always executes click on element
click() on it 2 or more times, I ensured it was first set in focus prior to being clicked. This fixed it for...
Read more >
click - Cypress Documentation
Click all elements with id starting with 'btn'​​ By default, Cypress will error if you're trying to click multiple elements. By passing {...
Read more >
How to handle Click Events in Cypress | BrowserStack
Read tutorial to perform different click events such as click, right-click, double-click, and trigger event in Cypress using examples.
Read more >
Solve The First Click - Gleb Bahmutov
Recently I wrote a blog post Cypress Module Problem where I tested a sample Svelte Kit ... cy.get(incrementSelector).click().click();
Read more >
8 Tricks I Learned From Cypress - Blog - ServMask
When we first started working on the end-to-end tests, we used Selenium with ... it('File triggers file dialog', function() { cy.get('@button').click() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found