Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  110] [ 3]  / answers: 1 / hits: 23777  / 5 Years ago, fri, march 29, 2019, 12:00:00

I would like to hide an element by setting the display property.



I've tried using invoke to set the attribute value, but it may only work for HTML attributes?



cy.get('#hubspot-messages-iframe-container > iframe')
.invoke('attr', 'display', 'none!important')
.should('have.attr', 'display', 'none!important')


This seems to be setting the attribute values, but the element is still visible, which leads me to believe it's probably not recognizing my attribute or i'm using the wrong command.



Tried using this as suggested:



enter



The .css() function seems to not be setting the value the way it should:



enter



Here's me validating my own sanity that the selector is correct and the display is none lol:
enter


More From » jquery

 Answers
35

This seems to work folks. I believe initial !important is a reference of some sort and not an actual value and maybe that's why .css() wouldn't work.



Cypress.Commands.add('hideHubSpot', () => {
cy.get('#hubspot-messages-iframe-container')
.invoke('attr', 'style', 'display: none')
.should('have.attr', 'style', 'display: none')

[#52333] Sunday, March 24, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austonjuancarlosb

Total Points: 238
Total Questions: 89
Total Answers: 99

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;