我的前端自动化套件在Selenium Cucumber中运行,不幸的是chrome驱动程序无法找到该元素。该服务器具有网络连接,我能够从CI服务器ping通URL。
[14:35:40][Step 1/1] org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of Proxy element for: DefaultElementLocator 'By.id: login_email' (tried for 60 second(s) with 500 milliseconds interval)
[14:35:40][Step 1/1] at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
[14:35:40][Step 1/1] at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
[14:35:40][Step 1/1] at stepdefs.LoginSteps.iFillEmailWithValidEmailAddress(LoginSteps.java:115)
[14:35:40][Step 1/1] at ?.When I fill email with valid OTA email address(login.feature:6)
[14:35:40][Step 1/1] Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"login_email"}
[14:35:40][Step 1/1] (Session info: headless chrome=69.0.3497.100)
[14:35:40][Step 1/1] (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.9.0-6-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)
[14:35:40][Step 1/1] Command duration or timeout: 0 milliseconds
[14:35:40][Step 1/1] For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
[14:35:40][Step 1/1] Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
[14:35:40][Step 1/1] System info: host: 'intelligence-teamcity', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.0-6-amd64', java.version: '1.8.0_181'
[14:35:40][Step 1/1] Driver info: org.openqa.selenium.chrome.ChromeDriver
[14:35:40][Step 1/1] Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.42.591071 (0b695ff80972cc..., userDataDir: /appdata/TeamCity/buildAgen...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:20897}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 69.0.3497.100, webStorageEnabled: true}
[14:35:40][Step 1/1] Session ID: d4f4672a9d49645e1bc8af8b54627aae
这是我如何创建Chrome驱动程序实例的方法。
System.setProperty("webdriver.chrome.driver",
"browser-drivers/chromedriver");
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--allow-running-insecure-content");
chromeOptions.addArguments("window-size=1920x1080");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--disable-extensions");
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.addArguments("--proxy-server='direct://'");
chromeOptions.addArguments("--proxy-bypass-list=*");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
chromeDriver = new ChromeDriver(capabilities);
我在这里做错了什么?为什么它可以在我的服务器上而不是在服务器上运行(它还安装了Chrome)?任何帮助将不胜感激。
更新:与UI一起运行时,效果很好。只是没头没用
答案 0 :(得分:1)
看起来无头模式不支持不安全的证书,然后页面将无法打开,只打开一个空白页面而在其中找不到任何内容。
只需将这两个功能(除了 chromeOptions 之一)添加到DesiredCapabilities对象即可:
capabilities.setCapability("acceptSslCerts", true);
capabilities.setCapability("acceptInsecureCerts", true);
答案 1 :(得分:0)
在前端测试的日子里,我遇到过类似的问题。尝试降级为稳定的Chrome / Chrome驱动程序版本,看看是否可以解决问题。在大多数情况下,仅通过降级到某些版本即可解决此类非理性问题。