0

我正在使用网格模式运行硒测试。每当我无法在页面中找到元素时,我都会收到以下异常

“对 URL http://localhost:4444/wd/hub/session/5fe58b67-491c-4b72-9a3a-a6dc790cc29d/element的远程 WebDriver 服务器的 HTTP 请求 在 60 秒后超时。”

我期待一个类似于NoSuch Element found的异常。但我正在超时。对此的任何指示都会很有帮助

代码如下

try
{
    switch (findBy.ToLower())
    {
        case "classname":
            webElement = driver.FindElement(By.ClassName(findByValue));
            break;
        case "cssselector":
            webElement = driver.FindElement(By.CssSelector(findByValue));
            break;
        case "id":
            webElement = driver.FindElement(By.Id(findByValue));
            break;
        case "linktext":
            webElement = driver.FindElement(By.LinkText(findByValue));
            break;
        case "name":
            webElement = driver.FindElement(By.Name(findByValue));
            break;
        case "partiallinktext":
            webElement = driver.FindElement(By.PartialLinkText(findByValue));
            break;
        case "tagname":
            webElement = driver.FindElement(By.TagName(findByValue));
            break;
        case "xpath":
            webElement = driver.FindElement(By.XPath(findByValue));
            break;
    }
}
catch (Exception e)
{
    return null;
}

非常感谢

4

1 回答 1

0

Pankaj Katiyar 认为超时是正确的,因为您使用的是显式等待。Selenium 也带有隐式等待,即等待多长时间(以秒为单位),如果元素仍未出现,请继续。

您也可以尝试使用 wait until 预期条件并将它们添加到所有 switch case 语句中。

于 2016-03-03T06:04:51.263 回答