Reputation: 3279
I am currently trying to learn Cypress for Automation testing.
I want to find and click on this element:
<input type="email" class="form-control text-ellipsis-global GKMU5SYDM3B" id="gwt-uid-1419" data-empty="true">
I can't use the id, or that 'GKMU5SYDM3B' because these are both randomly generated by GWT.
I expect my command to resemble this:
cy.get('input').type('email').click().type('[email protected]')
.should('have.value', '[email protected]')
I tried this one and got the following error message:
CypressError: cy.type() can only be called on a single element. Your subject contained 4 elements.
Upvotes: 3
Views: 12980
Reputation: 496
Actually you want to verify the typed 'email' in email's field.
First , type 'email' by using this type of locator.
cy.get("[type='email']").type('[email protected]');
After type in 'email' field you can verify it by this assertion.
cy.get("[type='email']").should('have.value', '[email protected]')
Upvotes: 0
Reputation: 13817
This should work.
cy.get("[type='email']")
cy.get("[type='email']").type('[email protected]')
What I always do, is try it in JQUERY first in the browser console. You should not have to click it to type into it.
if you have some parent element around, like a div you might also want to include that.
<div id='parent'>
<input type="email" class="form-control text-ellipsis-global GKMU5SYDM3B" id="gwt-uid-1419" data-empty="true">
</div>
so you would then go
cy.get('#parent').find("[type='email']").type('[email protected]')
Upvotes: 6