0

HTML:

<!-- Block 1--> <div class="row"> <div> <span>Type</span> </div> <div> <iput class="ant-select-dropdown-menu-item" placeholder="Input value"></iput> </div> </div> <!-- Block 2--> <div class="row"> <div> <span>Type</span> </div> <div> <iput placeholder="Input value"></iput> </div> </div> <!-- Block ..N --> <div class="row"> <div> <span>Type</span> </div> <div> <iput placeholder="Input value"></iput> </div> </div> 

JS:

for(let i = 0; i < 4; i++) { cy.contains('div', 'Type') .next() .find('div') .eq(i) .click({ multiple: true }) cy.get('.ant-select-dropdown-menu-item') .eq(i) .type(`value ${i}`) } 

There are many bloks with input field for each. I want to input value for each. I make cycle but value is inputted only in the first input value. How can I solve this for each input field?

3 Answers 3

1

You could find all instances of the elements and then use .each() to iterate over them.

cy.contains('div', 'Type') .each(($el, index) => { cy.wrap($el).siblings('div').click(); cy.get('.ant-select-dropdown-menu-item').eq(index).type(`value ${index}`); }) 
Sign up to request clarification or add additional context in comments.

4 Comments

the value is entered only in the first input
Do you have a separate list of inputs that you want to use? Or are there multiple values return from .ant-select-dropdown-menu-item? If so, you can use an .each() on that get as well. I'll update my answer if that's the case.
The value is inputted in the first input field each times of the circle
So you want to iterate over each .ant-select-dropdown-menu-item that you find?
1

Considering this is the input element <input placeholder="Input value"></input>, you can directly apply each on this. I will consider input as the selector as I don't have the exact HTML.

cy.get('input').each(($ele, index) => { cy.wrap($ele).type(`value ${index}`) }) 

7 Comments

Your code is like previous answer and it doesn't work
The code that I wrote is based on an assumption that I mentioned in the Answer. To get an exact answer, please add the exact HTML of the page and also mention what kind of error you are getting.
I don't receive error. I have problem that value was inputted ONLY in the first input field each loop
add the exact HTML of the page
My code doesn't require divs. It directly iterates on the input field. So if the code as you mention in the question is exactly similar to the original HTML than the above code should work perfectly
|
0
for(let i = 0; i < 4; i++) { cy.get('*[class^="row "]') .eq(i) .contains('div', 'Type') .next() .find('div') .eq(i) .click({ multiple: true }); cy.get('.ant-select-dropdown-menu-item') .eq(i) .type(`value ${i}`) } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.