admin管理员组文章数量:1287580
This is my cypress code:
cy.get(`${sitestovisit.searchBoxFormID} > form`)
.should('have.attr', 'target')<br>
.invoke('removeAttr', 'target')
sitestovisit.searchBoxFormId
contains data from JSON and its working properly but it shows that there is a target attribute in form, but when I tried to remove it, it is not working.
and when i replace above code with:
cy.get('#booking_search > form')
.invoke('removeAttr', 'target')
it works fine, what's the problem? i can't use directly cause I need it in loop Here's the output
This is my cypress code:
cy.get(`${sitestovisit.searchBoxFormID} > form`)
.should('have.attr', 'target')<br>
.invoke('removeAttr', 'target')
sitestovisit.searchBoxFormId
contains data from JSON and its working properly but it shows that there is a target attribute in form, but when I tried to remove it, it is not working.
and when i replace above code with:
cy.get('#booking_search > form')
.invoke('removeAttr', 'target')
it works fine, what's the problem? i can't use directly cause I need it in loop Here's the output
Share Improve this question edited May 2, 2023 at 11:37 Haast 1817 bronze badges asked Dec 2, 2019 at 16:11 Biki MaharjanBiki Maharjan 3981 gold badge3 silver badges11 bronze badges3 Answers
Reset to default 8Is failing because you have this assertion .should('have.attr', 'target')
before this invocation .invoke('removeAttr', 'target')
.
The .should('have.attr', 'target')
changes the subject from the element to the attribute, but .invoke('removeAttr', 'target')
requires the subject to be the element in order to work.
this will work
cy.get(`${sitestovisit.searchBoxFormID} > form`)
.invoke('removeAttr', 'target')
And.. if you need to see if the target attribute exist before deleting it I would do this.
cy
.get(`${sitestovisit.searchBoxFormID} > form`)
.should('have.attr', 'target')
cy
.get(`${sitestovisit.searchBoxFormID} > form`)
.invoke('removeAttr', 'target')
I´ll would use a then statement on the element yield by cy.get:
cy.get(`${sitestovisit.searchBoxFormID} > form`)
.then( $elem => {
$elem[0].removeAttribute('target');
})
Got this solution in Github thread. It should be added before you click the link.
cy.window().then((win) => {
const orig = win.open
win.open = function (url, target, features) {
return orig.call(this, url, '_self', features)
}
})
本文标签: javascriptcypress invoke(39removeAttr3939target39) not workingStack Overflow
版权声明:本文标题:javascript - cypress invoke('removeAttr', 'target') not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741224808a2361656.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论