嗨,我目前正在做的是访问网页“ http://the-internet.herokuapp.com/”,然后单击“基本身份验证”按钮,并使用AutoIT输入凭据,然后单击“确定”,现在我要实现的目标是以获取在单击警报框中的“确定”后不久出现的页面的当前URL。 我能够输入详细信息并成功转到下一页,但无法获取该页面的URL。我尝试了几件事,但它们似乎没有用。 我使用了POM,仅粘贴了测试用例的代码
package scripts;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.Assert;
import org.testng.annotations.Test;
import pages.BaseAuthLocators;
import sun.rmi.runtime.Log;
import testBase.Base;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class CheckValidBaseAuth extends Base{
public void Screenshot() throws IOException {
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("D:\\workspace\\Dave-Haeffner-s-Practice-Site\\src\\testUtility\\"+System.currentTimeMillis()+".png"));
}
@Test
public void BaseAuthSuccess() throws IOException, InterruptedException {
String expectedURL = "http://the-internet.herokuapp.com/basic_auth";
String actualURL;
BaseAuthLocators BaseAuthObj = new BaseAuthLocators(driver);
String parent=driver.getWindowHandle();
System.out.println(parent);
BaseAuthObj.clickBasicAuthLink();
System.out.println("Clicked Auth Button from webpage");
Runtime.getRuntime().exec("C:\\Users\\vishvesh.sawant\\Desktop\\AutoIT Scripts\\HandleAuthenicationWindow.exe");
//actualURL = driver.getCurrentUrl();
//System.out.println(actualURL);
/*
try
{
Assert.assertEquals(actualURL,expectedURL);
System.out.println(actualURL);
Screenshot();
}
catch (AssertionError e){
Log error;
System.out.println(actualURL);
Screenshot();
}*/
}
}
以下是我得到的错误:
org.openqa.selenium.UnhandledAlertException: :
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:22.379Z'
System info: host: 'IN-BOM01-NB04', ip: '10.44.1.158', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 62.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.22.0, moz:headless: false, moz:processID: 4136, moz:profile: C:\Users\vishvesh.sawant\Ap..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: a6d6ae04-493e-41ec-a701-ea2cecc4a0a2
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver.getCurrentUrl(RemoteWebDriver.java:335)
at scripts.CheckValidBaseAuth.BaseAuthSuccess(CheckValidBaseAuth.java:36)
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:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
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:348)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
答案 0 :(得分:0)
点击按钮后,您只需通过driver.getCurrentUrl()
即可获取