线程“main”org.openqa.selenium.nosuchframeexception中的异常:在centos 7的docker中使用selenium+java+chromedriver时没有这样的帧

wf82jlnq  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(611)

我有一个在我的windows机器上执行的测试可以正常工作,但是现在我正在尝试让它在docker中工作,centos 7,java版本1.8.0Đ272,chrome和chromedriver 87.0,但是它不工作,stacktrace说:

Starting ChromeDriver 87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-refs/branch-heads/4280@{#355}) on port 23699
All remote connections are allowed. Use an allowlist instead!
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[main] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Starting proxy at address: 0.0.0.0/0.0.0.0:0
[main] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Proxy listening with TCP transport
[main] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Proxy started at address: /0.0.0.0:34162
Nov 30, 2020 2:12:27 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.NoSuchFrameException: no such frame
  (Session info: headless chrome=87.0.4280.66)
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'b3782858cd26', ip: 'xxx.xx.x.x', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1127.el7.x86_64', java.version: '1.8.0_272'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 87.0.4280.66, chrome: {chromedriverVersion: 87.0.4280.20 (c99e81631faa0..., userDataDir: /tmp/.com.google.Chrome.Tp1C2S}, goog:chromeOptions: {debuggerAddress: localhost:39255}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(manual, http=proxy.cl..., setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: 8b9b8ef4dd9b0e870d8974c6f3b38e47
        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.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.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:872)
        at seleniumjavapqr.pqrMovil.pqrMovilRegistrar(pqrMovil.java:30)
        at seleniumjavapqr.myDriver.main(myDriver.java:128)
[LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Shutting down proxy server immediately (non-graceful)
[LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Closing all channels (non-graceful)
[LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.ServerGroup - Shutting down server group event loops (non-graceful)
[LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Done shutting down proxy server

排队 seleniumjavapqr.pqrMovil.pqrMovilRegistrar(pqrMovil.java:30) 我的密码是:

driver.switchTo().frame(0);

我不知道它有多重要,但是,在stacktrace第12行中,除了 selenium 信息之外,还有一个“未知”
作为重要信息,我可以说我将selenium-server-standalone.1.141.59.jar作为一个库导入到我的测试jar中,我不知道这是否正确。

6za6bjd0

6za6bjd01#

而不是在 <iframe> 使用索引作为:

driver.switchTo().frame(0);

理想情况下,您必须为 frameToBeAvailableAndSwitchToIt() 您可以使用以下任一定位器策略:
使用framename:

new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("frame_name")));

切换帧ID:

new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("frame_id")));

使用FramecsSelector:

new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("frame_cssSelector")));

使用framexpath:

new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("frame_xpath")));

参考

您可以在以下内容中找到一些相关的讨论:
iframe下文档的处理方法
在SeleniumWebDriverJava中,不使用driver.switchto().frame(“framename”)就可以切换到框架中的元素吗?

相关问题