最近使用到了 watir-webdriver, 在 mac 下使用火狐浏览器,去自动填充元素,在 ubuntu 下使用 headless,无界面去自动填充元素。
但是会碰到一个问题,连接超时
CarPublisher.browser.iframe(:id => "ContainerFrame").wait_until_present
#<URI::HTTP http://127.0.0.1:7055/hub/session/8f53eba2-13a2-f14e-97ec-36cfa00253ea/element>
"{\"using\":\"id\",\"value\":\"ContainerFrame\"}"
/Users/chuck/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.1/lib/watir-webdriver/wait.rb:44:in `until': timed out after 90 seconds, waiting for {:id=>"ContainerFrame", :tag_name=>"iframe"} to become present (Watir::Wait::TimeoutError)
而在打开的火狐浏览器里,这个 iframe, 早就出现了,而在等待 90s 后,selenium-webdriver 说它超时。
通过 selenium-webdriver, 相当于起了一个 server, 而要操作浏览器的元素,都是通过一个个的 command, 然后发送 get, post 请求来获取或变更元素信息
command :describeElement, :get, "session/:session_id/element/:id"
command :findChildElement, :post, "session/:session_id/element/:id/element"
command :findChildElements, :post, "session/:session_id/element/:id/elements"
command :clickElement, :post, "session/:session_id/element/:id/click"
command :submitElement, :post, "session/:session_id/element/:id/submit"
command :getElementValue, :get, "session/:session_id/element/:id/value"
command :sendKeysToElement, :post, "session/:session_id/element/:id/value"
command :uploadFile, :post, "session/:session_id/file"
command :getElementTagName, :get, "session/:session_id/element/:id/name"
command :clearElement, :post, "session/:session_id/element/:id/clear"
command :isElementSelected, :get, "session/:session_id/element/:id/selected"
command :isElementEnabled, :get, "session/:session_id/element/:id/enabled"
command :getElementAttribute, :get, "session/:session_id/element/:id/attribute/:name"
command :elementEquals, :get, "session/:session_id/element/:id/equals/:other"
command :isElementDisplayed, :get, "session/:session_id/element/:id/displayed"
command :getElementLocation, :get, "session/:session_id/element/:id/location"
command :getElementLocationOnceScrolledIntoView, :get, "session/:session_id/element/:id/location_in_view"
command :getElementSize, :get, "session/:session_id/element/:id/size"
command :dragElement, :post, "session/:session_id/element/:id/drag"
command :getElementValueOfCssProperty, :get, "session/:session_id/element/:id/css/:property_name"
command :getElementText, :get, "session/:session_id/element/:id/text"
有大神碰到过这种情况吗,或者说 ruby 下,有没更好的无头浏览器方案?