click() doesn't work on dropdown list item
See original GitHub issue- Operating System: Mac OS 10.13.3
- Cypress Version: 2.1.0
- Browser Version: Safari 11.0.3 and Chrome 65.0.3325.146
Is this a Feature or Bug?
Bug
Current behavior:
When I try to click on a specific list item in a dropdown of my app, Cypress finds it and says that it does click it. But it doesn’t trigger the event of the list item, so the value of the list item gets pushed into an input. It is definitely not a problem of the app as the click works in Nightwatch. But I can’t find out the reason why it isn’t working in Cypress.
Desired behavior:
Value of the clicked list item should appear in input and the test below should pass, as it happens when I click the list item manually.
How to reproduce:
See test code below. It should pass, but fails instead.
Test code:
it('selects element', () => {
cy.visit('https://app.liqid.de/investment-proposal/6PysBFc8AKr8J53jD1kkfY');
cy.get('.liq_recap-header__right-data-button').click();
cy
.get('.liq_recap-change-dropdown__body > :nth-child(4) [data-name=risk_level]')
.click()
.find('li[data-value=10]')
.click();
cy
.get('.liq_recap-change-dropdown__body > :nth-child(4) input[name=risk_level]')
.should('have.attr', 'value', '10');
});
Additional Info (images, stack traces, etc)
when I let the test time out when I click “10” in the dropdown manually while the test is still running
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
click event on select option element doesn't work [closed]
the event is on change of the select, and you get the option value by calling $(this).val(). this solves the issue of the...
Read more >Problem with a click activity on the item in the drop down list
You can either use Select Item activity to select items from the dropdown list. or else, you can use the Click Activity with...
Read more >jquery click event not working with dropdown menu element
Hi, I'm trying to add an event click on dropdown menu element. jQuery('#menu-item-518 a').click(function(){alert('clicked')});.
Read more >Excel Data Validation Tips and Troubleshooting - Contextures
Drop Down Opens With Blank Selected. When you click the arrow to open a drop down list on a data entry sheet, the...
Read more >How to use dropdown with a click event inside the navmenu?
If you use empty href on the a element, your app will be reloaded on link click. Maybe this is the cause of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Likely because the spec technically defines a
click
event as amousedown
andmouseup
over the same screen location. Perhaps it should be updated to account for the fact that theclick
was likely followed by amouseover
andmouseenter
event. https://www.w3.org/TR/uievents/#event-type-clickThe
click
code can be found here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/actions/click.coffee#L13Either that or wait for true native events https://github.com/cypress-io/cypress/issues/311
I solved the problem with adding
trigger('mouseover')
, so the code below makes the test pass again. Surprisingly, the test still fails when I trytrigger('mouseenter')
. I have to find out what is happening there.@jennifer-shehane Is there any reason why Cypress isn’t triggering
mouseover
with theclick()
command by default? This could break tests and lead to unexpected behaviour when someone is writing tests for code written by others (as in my case), as normally a click can’t happen without hovering the component first.