简体   繁体   中英

Force browser to load using Ruby with Watir and Webdriver

When I run the following code, I get a timeout waiting for the element:

require 'watir'
require 'webdrivers'

browser = Watir::Browser.new
browser.goto "http://watir.com/examples/forms_with_input_elements.html"
browser.text_field(:id, "new_user_username").set("test")

/home/.gem/ruby/2.4.1/gems/watir-6.9.1/lib/watir/elements/element.rb:618:in `raise_disabled': element present and enabled, but timed out after 30 seconds, waiting for # < Watir::TextField: located: true; {:id=>"new_user_username", :tag_name=>"input"}> to not be disabled (Watir::Exception::ObjectDisabledException)

The chrome window starts and doesn't seem to load. I can force it to load by resizing the window after it starts and everything works fine, but I should not have to take any manual steps. Is there an automated way to force the browser to load?

Ah, it's an interactable error. Those can't be easily figured out ahead of time. For some reason chromedriver doesn't think it can move the element to where it can enter text.

You can either try browser.window.maximize , or browser.window.move_to(x,y) or you can use Alex's excellent watir-scroll.gem to position the element inside the viewport where chromedriver can use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM