java - 模式中前两个字段的 key 未发送

标签 java c# selenium xpath selenium-webdriver

好的,那么自动化的流程是:

  1. 单击“添加地址”按钮。模态框出现但未完成加载
  2. 使用 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xPath)) 等待所有字段和按钮加载。
  3. 发送 key
  4. 选择“保存收件人”按钮

但是,在某些情况下,前两个 key 不会发送。我尝试过等待模式,但按键不太可能发送。 我使用了错误的 wait.until 参数吗?我是否在等待错误的元素?我假设现在发生了一些竞争情况

最佳答案

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

关于java - 模式中前两个字段的 key 未发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31481394/

相关文章:

java - 为 WebView 设置怪癖

java - 将 oracle 数据库的多行写入文本文件

C# 父窗体与子窗体之间的通信

C# 64 位应用程序,大内存地址感知

javascript - 使用JSE(Selenium c#)设置值和文本的区别

java - Selenium WebDriver 使用三个框架。无法找到该元素

java - 位级操作,从short值中获取位

c# - 基于不同因素的随机数生成

java - Selenium 许多日志(如何删除)

java - 如何知道压缩文件是否是 Jar 文件?