我不確定哪個更好。但它可以使用動態代理。只要創建一個實現ExpectedCondition
接口CFC:
component {
public boolean function apply(Any d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
}
然後創建代理的實例,並把它傳遞到的WebDriverWait
<cfscript>
driver = createObject("java", "org.openqa.selenium.firefox.FirefoxDriver").init();
driver.get("http://www.google.com");
by = createObject("java", "org.openqa.selenium.By");
element = driver.findElement(By.name("q"));
WriteDump("Page title is: "& driver.getTitle());
element.sendKeys(["Cheese!"]);
element.submit();
conditionProxy = createDynamicProxy("test.ExpectedConditionProxy", ["org.openqa.selenium.support.ui.ExpectedCondition"]);
WebDriverWait = createObject("java", "org.openqa.selenium.support.ui.WebDriverWait");
WebDriverWait.init(driver, 10).until(conditionProxy);
WriteDump("Page title is: "& driver.getTitle());
driver.quit();
</cfscript>
我得出一個結論的構造函數,移植WebDriverWait到帶有'sleep()'的CFML和while循環將是最安全的選擇。然後利用CF10的封閉來模仿上面的官方API。真棒! – Henry