为clojure webdriver设置页面加载超时

时间:2016-01-14 13:22:17

标签: selenium clojure webdriver

我正在使用clj webdriver,它在等待1800秒后抛出异常。这对我来说太长了,如何将它设置为120秒?我试图使用隐式等待,但它没有工作

 org.openqa.selenium.TimeoutException: Timed out waiting for page load.
Command duration or timeout: 1800.01 seconds
Build info: version: '2.47.1', revision: 'unknown', time: '2015-07-30 11:02:44'
System info: host: 'SomeHost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=31.0, platform=LINUX, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 7def8969-2487-4e63-b6d2-5981e3defff4

更新: 我使用以下内容来使用clojure获取firefox

 (require '[clj-webdriver.core :as cw])
(require '[clj-webdriver.firefox :as ff])
(defn get-checking-firefox [x]
  (let [directory (str "test" x)
        profile (doto (ff/new-profile (str "/home/oracle/.mozilla/firefox/" directory)))
        driver (cw/new-driver {:browser :firefox :profile profile})]
    (implicit-wait driver 120)
    (.. driver manage timeouts (pageLoadTimeout 30 TimeUnit/SECONDS))
    driver))

更新: 使用时

(.. driver manage timeouts (pageLoadTimeout 30 TimeUnit/SECONDS))

它抛出了

的错误
 java.lang.IllegalArgumentException: No matching field found: manage for class clj_webdriver.driver.Driver
at clojure.lang.Reflector.getInstanceField(Reflector.java:271)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:315)
at automate.core$get_firefox.invoke(core.clj:65)

如果我打印webdriver实例的方法/字段,则没有管理字段或方法:

automate.core=> (type a)
clj_webdriver.driver.Driver
automate.core=> (def b (reflect a)
           #_=> )
#'automate.core/b
automate.core=> (def c (:members b))
#'automate.core/c
automate.core=> (map println (map (fn[x] [(class x) (:name x)]) c))
[clojure.reflect.Method count]
[clojure.reflect.Method assoc]
[clojure.reflect.Method getLookupThunk]
[clojure.reflect.Field const__3]
[clojure.reflect.Field const__19]
[clojure.reflect.Field const__4]
[clojure.reflect.Method hashCode]
[clojure.reflect.Field const__23]
[clojure.reflect.Method keySet]
[clojure.reflect.Method entryAt]
[clojure.reflect.Field const__7]
[clojure.reflect.Method valAt]
[clojure.reflect.Method seq]
[clojure.reflect.Method empty]
[clojure.reflect.Method get]
[clojure.reflect.Constructor clj_webdriver.driver.Driver]
[clojure.reflect.Field const__2]
[clojure.reflect.Method containsValue]
[clojure.reflect.Field const__26]
[clojure.reflect.Field const__28]
[clojure.reflect.Method values]
[clojure.reflect.Method meta]
[clojure.reflect.Method put]
[clojure.reflect.Field const__29]
[clojure.reflect.Method isEmpty]
[clojure.reflect.Field const__15]
[clojure.reflect.Method without]
[clojure.reflect.Field cache_spec]
[clojure.reflect.Field const__10]
[clojure.reflect.Method size]
[clojure.reflect.Field const__12]
[clojure.reflect.Method assoc]
[clojure.reflect.Field const__13]
[clojure.reflect.Field const__8]
[clojure.reflect.Field const__22]
[clojure.reflect.Field const__30]
[clojure.reflect.Field __extmap]
[clojure.reflect.Field const__11]
[clojure.reflect.Method iterator]
[clojure.reflect.Method equals]
[clojure.reflect.Field const__18]
[clojure.reflect.Constructor clj_webdriver.driver.Driver]
[clojure.reflect.Method putAll]
[clojure.reflect.Field const__0]
[clojure.reflect.Method create]
[clojure.reflect.Field actions]
[clojure.reflect.Field const__27]
[clojure.reflect.Field webdriver]
[clojure.reflect.Field const__6]
[clojure.reflect.Field const__20]
[clojure.reflect.Method entrySet]
[clojure.reflect.Field const__14]
[clojure.reflect.Field const__24]
[clojure.reflect.Method cons]
[clojure.reflect.Method valAt]
[clojure.reflect.Method clear]
[clojure.reflect.Method withMeta]
[clojure.reflect.Field const__9]
[clojure.reflect.Field const__25]
[clojure.reflect.Method equiv]
[clojure.reflect.Method containsKey]
[clojure.reflect.Field __meta]
[clojure.reflect.Method getBasis]
[clojure.reflect.Field const__1]
[clojure.reflect.Method hasheq]
[clojure.reflect.Field capabilities]
[clojure.reflect.Field const__21]
[clojure.reflect.Field const__16]
[clojure.reflect.Field const__5]
[clojure.reflect.Field const__17]
[clojure.reflect.Method remove]

1 个答案:

答案 0 :(得分:2)

以下内容应设置30秒的页面加载超时:

(.. (:webdriver driver) manage timeouts (pageLoadTimeout 30 TimeUnit/SECONDS))

TimeUnit/SECONDS工作,您需要在ns表单中使用(:import [java.util.concurrent TimeUnit])