Java Selenium不等待元素可单击

Java Selenium不等待元素可单击,java,angular,selenium,selenium-webdriver,selenium-chromedriver,Java,Angular,Selenium,Selenium Webdriver,Selenium Chromedriver,嘿,我有一个问题,我试图解决了很长一段时间。 问题是,我希望selenium在屏幕上显示一条消息后,等待元素被单击 元素ID是:头帐户 我发送给方法的超时是:15500 我将隐式等待设置为:Implicit_WAITE=35 正如您所见,selenium不会等待一秒钟 这是我的主要观点: BasePage.waitInvisabilityOfElementByXpath("//div[@class='ant-notification ant-notification-topRight']")

嘿,我有一个问题,我试图解决了很长一段时间。 问题是,我希望selenium在屏幕上显示一条消息后,等待元素被单击

  • 元素ID是:头帐户
  • 我发送给方法的超时是:15500
  • 我将隐式等待设置为:Implicit_WAITE=35
  • 正如您所见,selenium不会等待一秒钟
这是我的主要观点:

BasePage.waitInvisabilityOfElementByXpath("//div[@class='ant-notification ant-notification-topRight']");
        System.out.println("\n\n Finished first wait \n\n ");
        By locator;
        locator = By.id("header-account");
        BasePage.waitForClickable(locator,15500);
        System.out.println("\n\n Finished second wait \n\n ");
        LoginHomeManager.logoutNoSleep();
我创建了这个方法:

 public static void waitForClickable(By locator, int timeOut) throws Exception {
        WebDriver driver = WebDriverMgr.getDriver();
        driver.manage().timeouts().implicitlyWait(IMPLICIT_WAITE, TimeUnit.SECONDS);
        Instant now = Instant.now();
        while (Instant.now().isBefore(now.plusSeconds(timeOut)))
        {
            try
            {
                new WebDriverWait(driver, timeOut).until(ExpectedConditions.elementToBeClickable(locator));

                return;
            }
            catch (WebDriverException e)
            {
                // do nothing, loop again
            }

        }

        throw new Exception("Not able to click element <" + locator + "> within " + timeOut + "s.");
    }
领事馆正在打印 System.out.println(“\n\n已完成第二次等待\n\n”)

这意味着它应该是可点击的,并且功能可以工作,但是实际上它没有工作

这是用户界面 我希望selenium等待显示的消息,然后按圆圈图标并注销。

这就是我所期望的


站点有角度

元素部分可见,因此
预期条件。元素可折叠
通过。它检查元素是否可见(它是)和已启用(它是)

Selenium尝试单击元素的中心位置,该位置被成功消息覆盖,因此出现异常

ElementClickInterceptedException: element click intercepted: Element <button id="header-account" is not clickable at point (1888, 31). Other element would receive the click: ...

抱歉,仍然没有运气,我尝试了WebDriverWait wait=newwebdriverwait(驱动程序,超时);WebElement=wait.until(ExpectedConditions.visibilityOfElementLocated(locator));我不知道如何处理wait.until(ExpectedConditions.invisibilityOf(element));因为我不知道被截获的元素是什么,它是:其他元素将收到点击:@Bastian the
wait。直到
是等待成功消息,而不是菜单按钮。您能检查信息并找到
X
按钮吗?我还将处理JavaScript消息添加到我的答案中。当我尝试Alert类时,它说它不是Alert。我尝试使用katalon recorder手动记录关闭消息,您能否澄清他是怎么做的:css=I.anticon.ant-notification-close-icon.anticon-close>svg.ng-tns-c0-2257
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
    at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.lambda$new$0(EventFiringWebDriver.java:404)
    at com.sun.proxy.$Proxy6.click(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:417)
    at com.blinkx.rx.ui.common.abstractionLayer.HomePage.clickAvatarNoSleep(HomePage.java:215)
    at com.blinkx.rx.ui.common.abstractionLayer.HomePage.clickLogoutNoSleep(HomePage.java:221)
    at com.blinkx.rx.ui.common.areaLibrary.LoginHomeManager.logoutNoSleep(LoginHomeManager.java:223)
    at com.blinkx.rx.ui.common.tests.EXPublisherSignUp.FinalPUbOpsApproval(EXPublisherSignUp.java:244)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
ElementClickInterceptedException: element click intercepted: Element <button id="header-account" is not clickable at point (1888, 31). Other element would receive the click: ...
WebDriverWait wait = new WebDriverWait(driver, timeOut);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("i.anticon.ant-notification-close-icon.anticon-close > svg")));
element.click();
wait.until(ExpectedConditions.invisibilityOf(element));