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

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

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

  1. Starting ChromeDriver 87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-refs/branch-heads/4280@{#355}) on port 23699
  2. All remote connections are allowed. Use an allowlist instead!
  3. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
  4. ChromeDriver was started successfully.
  5. [main] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Starting proxy at address: 0.0.0.0/0.0.0.0:0
  6. [main] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Proxy listening with TCP transport
  7. [main] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Proxy started at address: /0.0.0.0:34162
  8. Nov 30, 2020 2:12:27 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  9. INFO: Detected dialect: W3C
  10. Exception in thread "main" org.openqa.selenium.NoSuchFrameException: no such frame
  11. (Session info: headless chrome=87.0.4280.66)
  12. Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
  13. 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'
  14. Driver info: org.openqa.selenium.chrome.ChromeDriver
  15. 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}
  16. Session ID: 8b9b8ef4dd9b0e870d8974c6f3b38e47
  17. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  18. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  19. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  20. at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  21. at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
  22. at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
  23. at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
  24. at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
  25. at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
  26. at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
  27. at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:872)
  28. at seleniumjavapqr.pqrMovil.pqrMovilRegistrar(pqrMovil.java:30)
  29. at seleniumjavapqr.myDriver.main(myDriver.java:128)
  30. [LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Shutting down proxy server immediately (non-graceful)
  31. [LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Closing all channels (non-graceful)
  32. [LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.ServerGroup - Shutting down server group event loops (non-graceful)
  33. [LittleProxy-JVM-shutdown-hook] INFO org.littleshoot.proxy.impl.DefaultHttpProxyServer - Done shutting down proxy server

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

  1. driver.switchTo().frame(0);

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

6za6bjd0

6za6bjd01#

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

  1. driver.switchTo().frame(0);

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

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

切换帧ID:

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

使用FramecsSelector:

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

使用framexpath:

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

参考

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

展开查看全部

相关问题