我将Chrome更新为版本58后,无法切换到相框。 这是我的代码:
driver.switchTo().frame(frameId);
尝试使用另外两个重载 frame()方法(接受 index 和 WebElement ) - 同样的问题。
以下是例外:
org.openqa.selenium.NoSuchFrameException: no such frame: element is not a frame
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'slava', ip: '192.168.2.9', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.28.455520 (cc17746adff54984afff480136733114c6b3704b), userDataDir=C:\Users\SlavaM\AppData\Local\Temp\scoped_dir528_2137}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 14cb3f8dc100a369d4c99453b44cfe21
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:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:937)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:932)
at com.privowny.selenium.base.BaseTest.switchToFrame(BaseTest.java:251)
at com.privowny.selenium.base.BaseTest.openPasswordManagerSection(BaseTest.java:439)
at com.privowny.selenium.base.BaseTest.openPasswordListInPasswordManager(BaseTest.java:343)
at com.privowny.selenium.password.PasswordScoreTest.testPasswordsScoreRate(PasswordScoreTest.java:48)
at com.privowny.selenium.password.PasswordScoreTest.scoreTest(PasswordScoreTest.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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
对于Chrome 57,56及更早版本,一切正常。有什么想法吗?
UPD:这是真正的HTML。我们可以看到,那里没有iframe的内容:
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test page</title>
</head>
<div id="testBarBlock"
style="position: fixed; margin: -145.5px 0px 0px; overflow: visible; z-index: 2147483647; top: 50%; right: 0px; width: 60px; display: block;">
<div id="testHeaderBar"
style="position: absolute; width: 38px; height: 50px; background: rgb(52, 55, 56); padding: 0px 6px; right: 0px;">
<div id="testHeaderBarNav"
style="position: relative; height: 20px; border-bottom: 1px solid rgb(255, 255, 255);">
<div id="PBIframeHolderDraggable"
style="position: absolute; top: 5px; width: 10px; height: 10px; cursor: move; background-image: url("chrome-extension://gfhgplpdgglgiaafgmfhjabegdctest/app/images/bar/points.png"); background-size: cover; left: 0px;"></div>
<span id="testCollapseBar"
style="position: absolute; top: 5px; width: 10px; height: 10px; cursor: pointer; background-size: cover; background-image: url("chrome-extension://gfhgplpdgglgiaafgmfhjabegdctest/app/images/bar/arrowRight.png"); right: 0px;"></span><span
id="testExtendBar"
style="position: absolute; top: 5px; width: 10px; height: 10px; cursor: pointer; background-size: cover; display: none; background-image: url("chrome-extension://gfhgplpdgglgiaafgmfhjabegdctest/app/images/bar/arrowLeft.png"); right: 0px;"></span>
</div>
<img src="chrome-extension://gfhgplpdgglgiaafgmfhjabegdctest/app/images/logo.png" id="testLogo"
style="display: block; margin: 0px; padding: 0px; top: 22px; left: 10px; width: 27px; height: 27px; background: none; position: absolute; box-shadow: none;">
</div>
<div id="testIframeHolder"
style="width: 80px; height: 291px; position: absolute; overflow: visible; top: 50px;">
<iframe id="testIframeBar" name="barRightExpand" frameborder="0"
src="chrome-extension://gfhgplpdgglgiaafgmfhjabegdctest/app/modules/core/view/bar/bar.html"
style="width: 80px; height: 291px; border: 0px; padding: 0px; z-index: 2147483647; left: auto;"></iframe>
</div>
</div>
<body class="beautify">
<div class="ui-editor"><textarea class="ui-field json testIconExist" id="editor" spellcheck="false"
contenteditable="true">{"ID":null,"name":"Doe","first-name":"John","age":25,"hobbies":["reading","cinema",{"sports":["volley-ball","badminton"]}],"address":{}}</textarea><span
class="testActionIcon iconForInput" elemleft="0.00" elemtop="0.00"
style="width: 19px; height: 19px; left: 932px; top: 497.5px;"><img
src="chrome-extension://gfhgplpdgglgiaafgmfhjabegdctest/app/images/logo_up_primary.png"
class="imgtestActionIcon"></span>
<div class="ui-resizer"></div>
</div>
<div class="ui-aside">
<div class="ui-notification" id="status"></div>
<div class="ui-menu">
<div class="ui-menu-dropdown">
<div class="ui-menu-panel">
<div class="ui-menu-item ui-option" id="beautify">Beautify</div>
<div class="ui-menu-item ui-option" id="show-types">Show Types</div>
<div class="ui-menu-item ui-option" id="show-indexes">Show Indexes</div>
<div class="ui-menu-item about" style="display:none">About</div>
</div>
</div>
</div>
</div>
</body>
</html>
iframe中的HTML是从我的扩展程序加载的。它在UI上很好地显示,工作正常,但是当我检查元素时 - 那里没有内容。刚刚查看了Chrome 57 - 我可以在那里看到内容。
所以这是一个问题,我理解为什么selenium会给我这个错误。
现在的问题是Google Chrome决定隐藏iframe的内容,以及如何使用selenium测试我的iframe。有趣的是,我可以看到从外部资源(而不是从扩展名)加载的另一个iframe的html。