Vladimir_314159
Vladimir_314159

Reputation: 1677

Typing into a html box using cy.get with cypress/javascript not finding the id's

I am new to cypress/html and I am trying to type a address in the following address box

<input type="text" title="Street Address 1" name="billing[street][]" id="billing:street1" value="" class="input-text " autocomplete="address-line1">

so what I want to do is type something in this box so I write

cy.get('#billing:street1').type('1322 the gulag archipelago')

however I get the following error in cypress:

Expected to find '#billing:street1' but never found it.

So my question is why is this not working since I have done this .get by id before and it has worked.

Edit: could it be that i need to use 'billing:street1' or something similar in order to specify the meaning of the : . I tried this specifically and it did not work.

Thank you in advance.

Upvotes: 0

Views: 293

Answers (2)

Davin
Davin

Reputation: 86

There are multiple ways of doing this.

Using the element tag itself:

cy.get('input').type('1322 the gulag archipelago');

Using one of the attribute tags:

cy.get('[title="Street Address 1"'].type('1322 the gulag archipelago');

cy.get('[id="billing:street1"]).type('1322 the gulag archipelago');

cy.get('[class="input-text "]').type('1322 the gulag archipelago');

From within a form element:

cy.get('[sample-form-id="ExampleAddressForm"]').within(() => {
    cy.get('input').type('1322 the gulag archipelago');
});

If this is the third input on the page:

cy.get('input').then((inputs) => {
    cy.get(inputs[3]).type('1322 the gulag archipelago');
});

Upvotes: 1

Vladimir_314159
Vladimir_314159

Reputation: 1677

So here is how I got it working I can use a jQuery like command to query the title this is actually more robust anyway since the id could be changed but mostlikely the title will not be thus the command

cy.get('[title|="Street Address 1"]').type('1322 the gulag archipelago')

works just fine as you can do almost ll jQuery actions in cypress.

Upvotes: 0

Related Questions