How to resolve error "`assert_exists': unable to locate element"

Hi,

I am new to Watir webdriver and trying to write a small script which
gives input to text field.

Sample Code:


require ‘rubygems’
require ‘Watir-webdriver’
browser = Watir::Browser.new :chrome
browser.goto(“https://XXX.com”)
sleep 5
browser.text_field(:id => ‘uname’).set(“user1”)


If i execute with above code getting an error like “`assert_exists’:
unable to locate element, using {:id=>“uname”, :tag_name=>“input or
textarea”, :type=>”(any text type)"}
(Watir::Exception::UnknownObjectException)"

Please suggest…

Note that same pattern code(same syntax) is working fine with other
website. But for my required website not working.

Having some experience with Selenium, I can only guess that the field
that you are referring to, is not named ‘input or textarea’ or that it
does not have an id ‘uname’. Can’t you just verify the elements, that
the source of the targeted page provide you?

If the element, that you are referring to does not exist, well, then it
does not.

give it a try :

browser.element(:xpath => ‘//input[@type=“text”]’)