0

I am using the Ruby gem Capybara for automation purposes (having read the instructions on this website). I have a simple script that shows the problem I am having:

require 'capybara'
session = Capybara::Session.new(:selenium)
session.visit 'https://service.ringcentral.com/'
session.fill_in 'LoginName', with: '555-555-5555'

I have tried many different suggestions here on SO, and from other websites, with no success. I think this simply has something to do with the RingCentral website itself, because I do not have as much issue with other websites (such as google.com).

Grokify
  • 15,092
  • 6
  • 60
  • 81
singularity
  • 573
  • 4
  • 15

2 Answers2

1

Since the login field is invisible (opacity: 0 to allow the emptyText to show through from below) Capybara won't find it by default. You can pass visible: false to fill_in to find non-visible elements, and in this case that will then trigger focus on the element, which will trigger it to change to opacity: 1 and proceed to fill in the data.

require 'capybara'
session = Capybara::Session.new(:selenium)
session.visit 'https://service.ringcentral.com/'
session.fill_in 'login-form-username-field-LoginName', visible: false, with: '555-555-5555'
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Tested this and it works! I like the idea of just passing in the visible: false option to individual elements, rather than ignoring all hidden elements. – singularity Aug 15 '15 at 20:25
0

I found the solution here! Capybara by default ignores hidden elements. I wanted to post my answer because the other solution was so hard to find because I didn't know that the field I was trying to fill in was a hidden element, so I do not consider this post a duplicate. If you are having a difficult time getting Capybara to find and fill in fields, try setting the ignore_hidden_elements option to false, even if your field is completely visible.

require 'capybara'
session = Capybara::Session.new(:selenium)
Capybara.ignore_hidden_elements = false
session.visit 'https://service.ringcentral.com/'
session.fill_in 'login-form-username-field-LoginName', with: '555-555-5555'
Community
  • 1
  • 1
singularity
  • 573
  • 4
  • 15
  • 1
    Setting ignore_hidden_elements to false is a terrible suggestion 99% of the time, if you really need to find hidden elements in this case it's better to pass the visible: false option to fill_in. Most actions won't actually work with invisible elements though since a user couldn't actually interact with them – Thomas Walpole Aug 14 '15 at 15:33
  • The problem for me was not that I was trying to fill in a hidden field. The field is clearly visible if you go to the url. But for some reason, Capybara was treating it as a hidden field. Excellent input on adding the option to the fill_in method specifically though – singularity Aug 14 '15 at 19:28
  • 1
    It is actually invisible - since the div.x-form-emptyText is displayed over the top of it when its blank to simulate placeholder behavior across all browsers. – Thomas Walpole Aug 14 '15 at 19:49
  • 1
    To clarify that -- it's the other way -- the form field is positioned over top the div.x-form-emptyText but it has opacity:0 set so the emptyText shows through. This means the form field is invisible, but captures mouse clicks on itself to change the opacity to 1 and therefore make itself visible while hiding the emptyText – Thomas Walpole Aug 14 '15 at 20:12