DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on

[Capybara] find('input').set will have not done!

🔗 Parent Note

🤔 Situation

I have like this HTML and want to set a value into it.

<div class="bootstrap-dialog-message">
  <input type="text" class="form-control">
</div>
Enter fullscreen mode Exit fullscreen mode

😅 set finishes although it's not completed!

When capybara try to input the email,

find('input').set('loooooooooooooooooong@email.com')
Enter fullscreen mode Exit fullscreen mode

the results were like this. it's kind of random error.

1: loooo
2: loooooooooooooooooong@email.com
3: loooooooooooooooooong@e
.
.
Enter fullscreen mode Exit fullscreen mode

👍 Fix it!

Using Until

There is a method until ~ end. You can try again until the condition will succeed.

until find('input') == 'loooooooooooooooooong@email.com'
  find('input').set('loooooooooooooooooong@email.com')
end
Enter fullscreen mode Exit fullscreen mode

Using 10.times

10.times do
  find('input').set('loooooooooooooooooong@email.com')
  break if find('input') == 'loooooooooooooooooong@email.com'
end
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
sergioprats1 profile image
Sergio Prats López

In my case I was only able to write four characters and when I used larger strings I was getting the Selenium::WebDriver::Error::ElementNotInteractableError exception.