So let say I have an array called list that contains strings per below, when I loop through the array to send_keys each items from the array onto an online text editor element which already has focus:
list = ["First", "Second", "Third"]
for index in 0 ... list.size
line = list[index]
chain.send_keys(line).perform
if index < list.size
page.driver.browser.action.send_keys(:return).perform
end
end
The problem I'm facing is that instead of the output to look like this:
First
Second
Third
it instead looks like this:
First
First Second
First Second Third
Why is this happening ? is it because the previous actions are still in the action queue and have not cleared up ? or some other reason ? I'd appreciate if anyone can help.
When using the actions api it builds up a list of actions that are then executed by calling
perform
. Callingperform
however doesn't reset that list, so if you callperform
again it repeats the same actions. With the way you're calling itadds a
send_keys
action to chain - then performs it. Next time it adds another send_keys action to chain and then performs both actions. Solutions for that would be just create a new action chain each time rather than reusingchain
or callingchain.clear_actions
to clear the action chain each time through the loop.What isn't clear though is why you're using the action API at all rather than just calling send_keys on the element you want to send the keys too