gpt4 book ai didi

testing - Selenium如何获取警报Alert消息

转载 作者:行者123 更新时间:2023-11-28 20:04:04 26 4
gpt4 key购买 nike

您好,我正在使用下面的方法来检索警报消息数据,但是失败了

Alert alert = driver.switchTo().alert();
String ss1=alert.getText();

它显示以下错误消息。

Popup present/Not : true
FAILED: Login
org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server
did not provide any stacktrace information)
Command duration or timeout: 2.25 seconds
Build info: version: '2.23.0', revision: '17137', time: '2012-06-07 15:43:04'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1',
java.version: '1.7.0_17'
Driver info: driver.version: RemoteWebDriver
Session ID: 0c684096-46e6-4f00-8434-af866eb29746
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:458)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:462)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.alert(RemoteWebDriver.java:733)
at popupI_datachecking.Login(popupI_datachecking.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:128)
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:1203)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.run(TestNG.java:1036)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

============================================= 默认测试

测试运行:1,失败:1,跳过:0

最佳答案

在您的堆栈跟踪中基于此:

    org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server did not provide any stacktrace information)

Selenium 认为弹出窗口不存在,您可能需要等待它出现:

    WebDriverWait wait = new WebDriverWait(driver, 15, 100)
wait.until(ExpectedConditions.alertIsPresent())

上面的代码片段将使 selenium 等待最多 15 秒,以便警报出现,每 100 毫秒检查一次是否出现。

关于testing - Selenium如何获取警报Alert消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16273261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com