有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

未为modal中的前两个字段发送java密钥

好的,自动化的过程是:

  1. 单击添加地址按钮。模态显示,但未完成加载
  2. 使用Wait等待加载所有字段和按钮。直到(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath))
  3. 发送密钥
  4. 选择保存收件人按钮

但是,在一些情况下,前两个键不被发送。我已尝试等待模式,但钥匙不太可能发送。 我用错了等待时间。直到参数?我是否在等待错误的元素?我假设现在有一些比赛情况发生


共 (1) 个答案

  1. # 1 楼答案

    public static class WebDriverExtensions
    {
        /// <summary>
        /// Try finding the element for timeoutInSeconds until throwing "no matching element"
        /// </summary>
        public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
        {
            if (timeoutInSeconds <= 0) return driver.FindElement(@by);
    
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
            return wait.Until(drv => drv.FindElement(@by));
        }
    }
    

    那么你可以把这个叫做

    driver.FindElements(By.xpath(xPath),5).SendKeys(fieldOneString);
    

    其中xPath用于fieldOne