Reputation: 11
i am trying a drag and drop in an iframe and to do that i need to pass xpath in find since i cant find a unique element to pass in cy.get()
currently i am trying
cy.xpath('//div[@class="unlayer-editor"]//iframe[@src]')
.should("be.visible")
.find('//div[@class = "blopockbder-coent-tols43 col-sm-12"]//div[@aria-describedby="t8ppy-tooltip-9"]')
but this isnt working
i am using cypress for automation
Upvotes: 1
Views: 98
Reputation: 31944
Not an expert on xpath, but I think .find()
can't be mixed with an xpath selector.
Two things to try
// chain 2nd xpath in place of .find()
cy.get('div[class="unlayer-editor"] iframe[id="my-iframes-id"]')
.should("be.visible")
.xpath('//div[@class = "blopockbder-coent-tols43 col-sm-12"]//div[@aria-describedby="t8ppy-tooltip-9"]')
or
// use .within() instead of .find() (roughly equivalent)
cy.get('div[class="unlayer-editor"] iframe[id="my-iframes-id"]')
.should("be.visible")
.within(() => {
cy.xpath('//div[@class = "blopockbder-coent-tols43 col-sm-12"]//div[@aria-describedby="t8ppy-tooltip-9"]')
})
Other things that might need adjusting
The iframe
selection generally needs a follow-up command to get it's document body (ref Working with iframes)
// get the iframe document body any select within it
cy.get('div[class="unlayer-editor"] iframe[id="my-iframes-id"]')
.its('0.contentDocument.body', { log: false }).should('not.be.empty')
.within(() => {
cy.xpath('//div[@class = "blopockbder-coent-tols43 col-sm-12"]//div[@aria-describedby="t8ppy-tooltip-9"]')
})
Some of those classes in the path like col-sm-12
are purely display-oriented and may be different if you test at different devices. Once the test works, try removing them to make the test more robust.
Upvotes: 1