-1

我正在尝试从模式对话框中单击一个按钮,但是当该单击它时,我遇到了下一个错误:

OpenQA.Selenium.ElementClickInterceptedException : element click intercepted: Element <button onclick="Activar(193);" class="button mx-1" title="Recover">...</button> is not clickable at point (1206, 319). Other element would receive the click: <div class="ui-widget-overlay" style="width: 1349px; height: 613px; z-index: 1001;"></div>

我知道我需要使用等待助手,但我不知道如何使用它,这是我的等待助手代码:

 public ConfigurationUsuario HabilitarConfiguracion()
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
            iconoActivar.Click();
            driver.SwitchTo().ActiveElement();
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//button[@title='Recover']"))).Click();
            driver.FindElement(By.XPath("//button[@title='Recover']")).Click();
            return new ConfigurationUsuario(driver);
        }

可能是因为我不知道如何使用等待助手,但测试不要等待 20 秒,在模态对话框中 2-3 秒后,它会关闭,所以如果有人可以帮助我,我真的很感激

4

1 回答 1

2

尝试这个:

等待显示的元素:

前任。WaitForElementDisplayed_byXPathTime("//input[@id='id']");

    public static void WaitForElementDisplayed_byXPathTime(string value)
    {
        try
        {
            var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
            wait.Until(webDriver => driver.FindElement(By.XPath(value)).Displayed);
        }
        catch (Exception) { throw; }
    }

然后切换到弹出窗口 - 老实说,这甚至可能没有必要。并非所有弹出窗口都要求您切换到它们。

        public static string SwitchToPopup()
    {
        var mainHandle = driver.CurrentWindowHandle;
        var handles = driver.WindowHandles;

        foreach (var handle in handles)
        {
            if (mainHandle == handle)
            {
                continue;
            }
            driver.SwitchTo().Window(handle);
            Thread.Sleep(1000);
            break;
        }
        var result = Url;
        return result;
       
    }
于 2021-01-29T20:00:16.750 回答