使用php-webdriver脚本测试jquery自动完成


Testing jquery autocomplete using php webdriver script

请帮助我使用php-webdriver脚本测试jquery自动完成小部件。我是webdriver脚本的新手。

这是我的代码

require_once "./phpwebdriver/WebDriver.php";
require_once "./phpwebdriver/LocatorStrategy.php";
$webdriver = new WebDriver("127.0.0.1", "4444");
$webdriver->connect("chrome");
$webdriver->get("http://URL_TO_WEBSITE"); 
$webdriver->typeKeys("ELEMENT_ID_TO_FIND", "a");
for ((int) $second = 0;; $second++) {
    if ($second >= 60) fail("timeout");
    try { if ($webdriver.isTextPresent("apple")) break; } catch (Exception e) {}
    Thread.sleep(1000);
}
$webdriver->mouseOver("/html/body/ul/li/a[. = '"apple'"]");
$webdriver->click("/html/body/ul/li/a[. = '"apple'"]");

使用WebDriverWait类。为我解决了同样的问题。

C#中的解决方案

    driver.FindElement(By.Id("ajaxTextBox")).SendKeys(searchString);
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    wait.Until(x => x.FindElement(By.ClassName("li-menu-item")));