title: Cannot set text for form element using Watir in Ruby
body: <p>I have just started tinkering with watir after having successfully written some code to interact with a small web site hosted on my laptop using mechanize. But I am struggling to get watir to work at all.</p>
  
  <pre><code>require 'watir-webdriver'
  
  b = Watir::Browser.new :firefox
  b.goto('https://dev.mitdev.org.uk/login')
  body = b.body
  body.forms.each do |f|
    p f.name
    f.text_field(:name, 'IDToken1').wait_until_present(5).set('test')
  end
  </code></pre>
  
  <p>I find that printing f.name works and I see that the login form is called "Login". But if I add the line to set the text I get a timeout.</p>
  
  <p>Looking at FF I can see that the form has rendered so I'm puzzled as to why I can't seem to interact with it.</p>
  
  <p>I've tried other methods of setting the values like:</p>
  
  <pre><code>body.text_field(:name =&gt; 'IDToken2').wait_until_present(5).set('Password')
  </code></pre>
  
  <p>But to no avail. </p>
  
  <p>The tutorials online make this look so easy that I suspect I'm just making a rookie blunder and am too tired to see it.</p>
  
  <hr>
  
  <p>Thanks for the reply. As for the exception, I'm seeing it is not rendered unless I put in the wait and a timeout if I do. If there is a way of forcing it to tell me my syntax is in error I would appreciate knowing how to do that.</p>
  
  <p>Here is the form:</p>
  
  <pre><code>&lt;form id="Login" name="Login" action="/login" method="post"&gt;
      &lt;div class="sign-in"&gt;
          &lt;fieldset&gt;
              &lt;legend class="form-title heading-large"&gt;Sign in&lt;/legend&gt;
              &lt;div class="form-group"&gt;
                  &lt;label  class="form-label" for="IDToken1"&gt;
                      User ID
                  &lt;/label&gt;
                  &lt;input class="form-control" type="text" name="IDToken1" id="IDToken1" value="" maxlength="50" tabindex="1" /&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="form-label" for="IDToken2"&gt;
                      Password
                  &lt;/label&gt;
                  &lt;input type="hidden" id="goto" name="goto" value=""/&gt;
                  &lt;input class="form-control" type="password" name="IDToken2" id="IDToken2" value="" maxlength="100" autocomplete="off" tabindex="2" /&gt;
                  &lt;input type="hidden" name="_csrf_token" value=" deleted "&gt;
              &lt;/div&gt;
          &lt;/fieldset&gt;
          &lt;nav class="module-content-navigation"&gt;
              &lt;input name="Login.Submit" type="submit" class="button" value="Sign in" tabindex="3" /&gt;
              &lt;ul class="content-navigation__secondary"&gt;
                  &lt;li&gt;
                      &lt;a href="/forgotten-password" tabindex="4"&gt;Forgotten password&lt;/a&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/nav&gt;
      &lt;/div&gt;
      &lt;input name="IDButton" type="hidden" style="display: none;"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I've discovered a good tutorial online that has showed me how to use a hash to further qualify the address of the element but I'm still having no luck with this form:</p>
  
  <pre><code>b = Watir::Browser.new
  b.goto('https://dev.mitdev.org.uk/login')
  b.wait(3)
  b.text_field(:class =&gt; 'form-control',
               :type =&gt; 'text',
               :name =&gt; 'IDToken1',
               :id =&gt; 'IDToken1').set('test')
  </code></pre>
  
  <p>I'm still getting an exception for a timeout or with no wait:</p>
  
  <pre><code>[remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-12708-sjjxdp/extensions/fxdriver@googlecode.com/components/command-processor.js:10092:in `fxdriver.preconditions.visible': Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)
      from [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-12708-sjjxdp/extensions/fxdriver@googlecode.com/components/command-processor.js:12644:in `DelayedCommand.prototype.checkPreconditions_'
      from [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-12708-sjjxdp/extensions/fxdriver@googlecode.com/components/command-processor.js:12661:in `DelayedCommand.prototype.executeInternal_/h'
      from [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-12708-sjjxdp/extensions/fxdriver@googlecode.com/components/command-processor.js:12666:in `DelayedCommand.prototype.executeInternal_'
      from [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-12708-sjjxdp/extensions/fxdriver@googlecode.com/components/command-processor.js:12608:in `DelayedCommand.prototype.execute/&lt;'
  </code></pre>
  
  <p>Zeroing in a little more, this prints the id of the text field:</p>
  
  <pre><code>p b.text_field(:type =&gt; 'text',
               :name =&gt; 'IDToken1',
               :id =&gt; 'IDToken1').id
  </code></pre>
  
  <p>but this fails to set the text:</p>
  
  <pre><code>b.text_field(:type =&gt; 'text',
               :name =&gt; 'IDToken1',
               :id =&gt; 'IDToken1').when_present(5).set('test')
  </code></pre>
  
  <p>This is looking more and more like something to do with the page rather than my grasp of water syntax:</p>
  
  <pre><code>p b.text_field(:name =&gt; /Token1/).name
  p b.text_field(:type =&gt; 'text',
               :name =&gt; 'IDToken1',
               :id =&gt; 'IDToken1').id
  p b.text_field(:name =&gt; /Token1/).exists?
  b.text_field(:name =&gt; /Token1/).double_click
  b.text_field(:name =&gt; /Token1/).set 'test'
  </code></pre>
  
  <p>Gives me this output that shows the element clearly exists but I see this weird "scroll" stack trace for the double click.</p>
  
  <pre><code>"IDToken1"
  "IDToken1"
  true
  [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-2812-w3soqr/extensions/fxdriver@googlecode.com/components/driver-component.js:11072:in `FirefoxDriver.prototype.mouseMoveTo': Offset within element cannot be scrolled into view: (5, 17.5): [object HTMLInputElement] (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)
      from [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-2812-w3soqr/extensions/fxdriver@googlecode.com/components/command-processor.js:12661:in `DelayedCommand.prototype.executeInternal_/h'
      from [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-2812-w3soqr/extensions/fxdriver@googlecode.com/components/command-processor.js:12666:in `DelayedCommand.prototype.executeInternal_'
      from [remote server] file:///var/folders/f4/6vwp2t_d75v803226gs84v100000gp/T/webdriver-profile20160612-2812-w3soqr/extensions/fxdriver@googlecode.com/components/command-processor.js:12608:in `DelayedCommand.prototype.execute/&lt;'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/response.rb:70:in `assert_ok'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/http/common.rb:78:in `new'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/http/common.rb:78:in `create_response'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/http/default.rb:90:in `request'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/bridge.rb:649:in `raw_execute'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/bridge.rb:627:in `execute'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/remote/bridge.rb:419:in `mouseMoveTo'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/common/mouse.rb:71:in `move_to'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/common/mouse.rb:81:in `move_if_needed'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/common/mouse.rb:40:in `double_click'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/common/action_builder.rb:363:in `block in perform'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/common/action_builder.rb:362:in `each'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.1/lib/selenium/webdriver/common/action_builder.rb:362:in `perform'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:147:in `block in double_click'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:598:in `element_call'
      from /Users/atkinsb/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:147:in `double_click'
  </code></pre>
  
  <p>Feels like I'm getting closer to the problem:</p>
  
  <pre><code>p b.text_field(:name =&gt; /Token1/).exists?
  p b.text_field(:id =&gt; /Token1/).visible?
  p b.text_field(:name =&gt; /Token1/).present?
  </code></pre>
  
  <p>This show false for visible and present but true for exists.</p>
  
  <p>Why this element is invisible to watir while visible to me is the next question I must answer...</p>