当前位置: 首页 > 面试题库 >

将密钥发送到Input WebElement失败,因为它不是绝对路径

羿博延
2023-03-14
问题内容

我正在尝试使用Selenium测试将文档上传到特定网站-
如果我在本地运行测试,那么它们似乎可以正常工作。但是,如果我通过Jenkins运行它们,则会出现问题。我认为这可能是因为运行Java的测试是linux,但是浏览器是基于Windows机器的。在Chrome上有一个明显的错误-
在其他错误上,它们似乎根本无法加载。有谁知道解决此问题的方法吗?我觉得Chrome中的异常行为是引发异常的原因!

堆栈跟踪以确保完整性:

org.openqa.selenium.WebDriverException: unknown error: path is not absolute: /var/lib/jenkins/workspace/Tests - Chrome/console/integration-tests\src\test\resources\x\x.png
  (Session info: chrome=49.0.2623.110)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 28 milliseconds
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
System info: host: 'SELENIUM-01', ip: '16.46.34.8', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\1\scoped_dir5704_26570}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.110, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 11c5faf21b8defc3047621f3800e52d2
Command duration or timeout: 146 milliseconds
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'jenkins-05.ci.idolondemand.com', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-39-generic', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\1\scoped_dir5704_26570}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.110, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, webdriver.remote.sessionid=74aa79c8-201f-4147-9410-b0a4ea3cb66c, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 74aa79c8-201f-4147-9410-b0a4ea3cb66c
    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:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
    at com.hp.devconsole.apis.y.X.x(x.java:95)
    at com.hp.devconsole.apis.y.X.x(x.java:81)
    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:497)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    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:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:103)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:169)
    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:497)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'jenkins-05.ci.idolondemand.com', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-39-generic', java.version: '1.8.0_51'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:136)
    ... 44 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: path is not absolute: /var/lib/jenkins/workspace/Tests - Chrome/console/integration-tests\src\test\resources\x\x.png
  (Session info: chrome=49.0.2623.110)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 28 milliseconds
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
System info: host: 'SELENIUM-01', ip: '16.46.34.8', os.name: 'Windows Server 2012 R2', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\1\scoped_dir5704_26570}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.110, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 11c5faf21b8defc3047621f3800e52d2
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'jenkins-05.ci.idolondemand.com', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-39-generic', java.version: '1.8.0_51'
Driver info: driver.version: RemoteWebDriver
    at sun.reflect.GeneratedConstructorAccessor78.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:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:122)
    at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:335)
    at com.sun.proxy.$Proxy2.sendKeys(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.sendKeys(EventFiringWebDriver.java:358)
    at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.openqa.selenium.remote.server.KnownElements$1.invoke(KnownElements.java:64)
    at com.sun.proxy.$Proxy3.sendKeys(Unknown Source)
    at org.openqa.selenium.remote.server.handler.SendKeys.call(SendKeys.java:50)
    at org.openqa.selenium.remote.server.handler.SendKeys.call(SendKeys.java:1)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

无论斜杠是否都在正确的位置,实际上都会发生这种情况-上一次运行时出现了相同的错误:

unknown error: path is not absolute: /var/lib/jenkins/workspace/Tests - Chrome/console/integration-tests/src/test/resources/text/dog.txt

更新2

当路径名中没有空格时也会发生这种情况,例如

unknown error: path is not absolute: /var/lib/jenkins/workspace/chrome_main/console/integration-tests/target/test-classes/containers/tarFile.tar

代码:

view.selectFileButton().sendKeys(getResourceAbsolutePath("text/dog.txt"));

getResourceAbsolutePath在哪里(尝试了几种不同的操作之后):

protected String getResourceAbsolutePath(String url) throws FileNotFoundException {
    try {
        return new File(getClass().getClassLoader().getResource(url).toURI()).getPath();
    } catch (URISyntaxException e) {
        throw new FileNotFoundException("Could not find file with url " + url);
    }
}

问题答案:

发生的事情是,当从另一个项目中提取某些代码时(认为与我正在使用的项目中的代码相同),驱动程序在将其文件检测器设置为本地文件检测器的位置丢失了。所有需要做的就是通过在代码开头执行以下操作来纠正此问题:

driver.setFileDetector(new LocalFileDetector());


 类似资料:
  • 问题内容: 由于某种原因,我无法将字符“ 3”写入页面上的输入元素。 这段代码: 导致在登录输入中写入“ 1245” …有人可以帮忙吗?我使用python 2.7,最新的chrome和最新的chromedriver 编辑: 也不管用。 -字符串中仅缺少“ 3” … 起作用的是 正如安德森(Andersson)在下文中建议的那样,但这不是解决方案。 我在Google搜索框中进行了尝试,并且遇到了相同

  • 我正在使用8.5.0运行时服务器运行我的项目,在部署期间,我发现以下错误 这里是配置。引用密钥存储的xml文件。资源目录中的jks文件

  • 我的代码: 我已经试过了,而不是。getFile(),extractJarFileFromURL或资源。getInputStream(),但所有这些都不起作用。当我打包项目并将其作为jar文件运行时,它试图打开以下文件,它总是返回以下消息。 错误: java.io.FileNotFoundException:类路径资源[资产/OPTIONS_DE. docx]无法解析为绝对文件路径,因为它不驻留在

  • 我正在尝试对我的进行测试,但是它总是说找不到用户名而失败。我已经将这个问题缩小到中检查是否找到User==null的行。 这里是我的 还有我的 而我的 失败的行是在中,它试图找到UserByEmail,因为userRepository被嘲笑了,它只是返回null并抛出username not search异常。如果我删除了Mock,那么我的测试失败了,因为它找不到中构造函数所需的UserRepos

  • 问题内容: 我正在尝试使用以下pythonselenium代码将密钥发送到以下字段 Selenium Python代码: 我没有收到任何错误或异常,但无法将密钥发送到此元素中。我是python selenium的新手,如果有人可以建议如何将密钥发送到只读字段,我将不胜感激。 问题答案: 发送键之前,请删除输入的 readonly 属性:

  • 问题内容: 我有文件A的绝对路径。 我有一个从文件A的目录到文件B的相对路径。此路径可以并且将使用“ ..”以任意复杂的方式向上移动目录结构。 范例A: 示例B: 我如何结合这两者以获得 最简单的 绝对路径到文件B? 问题答案: 如果我的问题正确,那么您可以执行以下操作: