Paypal checkout中的异常处理,无法访问iframe元素的id

时间:2018-02-09 14:18:54

标签: selenium

我有一个电子商务网站,当我尝试下订单时,它会重定向到Paypal页面。当我以Paypal用户身份登录时,它会重定向到另一个结帐屏幕,我尝试使用selenium web驱动程序进行自动化。

在此步骤中,我收到以下异常(我尝试使用Println方法访问iframe):

Chrome版本64.0.3282.140(官方版)(64位)     Selenium Server Standalone jar:3.9.1

[TestNG] Running:
  C:\Users\MVN020\AppData\Local\Temp\testng-eclipse--1759291335\testng-customsuite.xml

Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 39463
Only local connections are allowed.
size3
size3
size1
FAILED: f
org.openqa.selenium.NoSuchFrameException: no such frame
  (Session info: chrome=64.0.3282.140)
  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 8 milliseconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'GOKAL', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_40'
Session ID: 4b02279f3819eced46aa69a5c4f37004
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\MVN020\AppData\Local\Temp\scoped_dir12284_24522, chromedriverVersion=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, setWindowRect=true, locationContextEnabled=true, mobileEmulationEnabled=false, version=64.0.3282.140, pageLoadStrategy=normal, takesHeapSnapshot=true, databaseEnabled=false, cssSelectorsEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
    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:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:857)
    at automationFramework.CodePaypal.f(CodePaypal.java:86)
    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: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: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:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    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)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@143f45a8: 22 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@7595edfe: 8 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 5 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1b814a5: 25 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@7aee64f1: 4 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@3ed9a7a6: 15 ms

1 个答案:

答案 0 :(得分:0)

在这种情况下,问题可能是以下两个原因之一。

1.如果它重定向到新窗口而没有切换到新窗口,则无法访问新窗口的任何定位器。您可以使用以下代码切换窗口

 String Parent_Window = driver.getWindowHandle(); 
 //Get Parent window handle befor child window opens
 String winHandleBefore = _driver.getWindowHandle();
 for (String winHandle : _driver.getWindowHandles()) {
   // Switch to child window
   if( Parent_Window != winHandle )
   driver.switchTo().window(winHandle);
 }

在子窗口中执行操作并切换回父窗口。

  1. 如果它没有重定向到新窗口并且您的定位器是正确的,则问题可能是,您正在寻找的帧是其他帧的子帧。在这种情况下,您可能必须先切换到父框架,然后再切换到子框架。
  2. 希望这会奏效。