等待,直到使用Java在selenium网络驱动程序中手动单击登录按钮

Wait until login button is manually clicked in selenium webdriver using Java

本文关键字:驱动程序 单击 按钮 登录 网络 selenium Java 等待      更新时间:2023-09-26

在Selenium Webdriver中,是否可以使用webdriver.wait暂停代码执行,直到用户单击表单的登录按钮?表单中包含一个用户必须手动填写的Captcha,因此我无法使用脚本自动单击按钮。点击登录按钮会以布尔值的形式返回JavaScript函数的值,即true或false。

这个问题有什么可能的解决方案吗?

编辑:获取更多信息后的全新响应。

下面的代码就是这样:

  1. Selenium进入用户数据
  2. 然后我手动刷新页面(因为我没有要测试的登录数据)
  3. Selenium再次输入用户数据

(变量W是早期定义的WebDriverWait。)

       driver.Navigate().GoToUrl("https://www.irctc.co.in/eticketing/loginHome.jsf");
        // will try looping as long as you're on the relevant page
        do
        {
            try
            {
                IWebElement username = w.Until(ExpectedConditions.ElementIsVisible(By.Id("usernameId")));
                IWebElement password = driver.FindElement(By.Name("j_password"));
                if (String.IsNullOrEmpty(username.GetAttribute("value")))
                {
                    username.SendKeys("a");
                    password.SendKeys("b");
                }
            }
            catch (Exception)
            { 
                // page is reloading, just wait another round
            }
        } while (!String.Equals(driver.Url, "put url after login here"));