Locating a input of type email with SafariWatir

488 views Asked by At

I just started using Watir to write some simple tests for my web application.

First thing I want to do is to populate an login form with an email input element of type "email" with SafariWatir on OS X.

This won't work:

browser.text_field(:id, "email").set('[email protected]')

Trace:

/Library/Ruby/Gems/1.8/gems/safariwatir-0.4.0/lib/safariwatir/scripter.rb:661:in `execute': Unable to locate TextField, using :id and "email" (Watir::Exception::UnknownObjectException)
    from /Library/Ruby/Gems/1.8/gems/safariwatir-0.4.0/lib/safariwatir/scripter.rb:303:in `focus'
    from /Library/Ruby/Gems/1.8/gems/safariwatir-0.4.0/lib/safariwatir.rb:525:in `set'
    from test.rb:10

I assume that the element is not matched because of the different type attribute value. The documentation does not state any specification for this kind of elements. Any ideas?

Thanks!

Update: adding (reformatted) HTML sample based on user's comment that they are testing pinganalytics

<form action="http://pingalytics.com/" method="post" accept-charset="utf-8"> 
  <p>
    <label for="email">Email</label> 
    <input type="email" name="email" value="" id="email" autofocus=""  /> 
  </p>
  <p>
    <label for="password">Password</label>
    <input type="password" name="password" value="" id="password"  /> 
  </p>
  <input type="submit" name="login" value="Log in with Pingdom" class="primary" />
  <p>
    <a href="https://www.pingdom.com/signup/">
      Sign up
    </a>
    , or 
    <a href="https://pp.pingdom.com/index.php/login" title="Reset your Pingdom password">
      recover your password
    </a>
    .
  </p>
</form>
1

There are 1 answers

0
Chuck van der Linden On BEST ANSWER

the 'email' type for an input element is new as of HTML5. Safariwatir is an older project which pretty much predates HTML5. It has not seen a lot of recent work and it is highly unlikely it would be looking for this type when searching for potential 'text_field' elements.

Watir 3.0 or Watir-webdriver would be a safer bet as a lot of work has gone into those to bring them up to properly supporting HTML5.

Also since Webdriver has just recently added support for Safari (see here for instructions), it is now a viable alternative to safariwatir (which I highly expect will see no further work going forward.) The Safari support is still a tiny bit DYI as you have to build your own safari extension and it only works on a Mac, but that may change if we see someone start publishing a standard safari extension that could be downloaded from an online gallery