Issue
path is not absolute: src/test/resources/testData/twt_Pic.jpg
getting this exception while uploading the file using selenium.
Instead of uploading the file using the native os file explorer, sending the keys to the path file.
The same path used to work during the older version, not sure which version was it.
Error Log in Chrome:
org.openqa.selenium.WebDriverException: unknown error: path is not absolute: src/test/resources/testData/twt_Pic.jpg
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.39.562713 (dd642283e958a93ebf6891600db055f1f1b4f3b2),platform=Mac OS X 10.13.4 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'nagarjunaMBP.local', ip: 'fe80:0:0:0:c2e:b816:67ae:922b%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.39.562713 (dd642283e958a9..., userDataDir: /var/folders/g4/dylg4g7s7wb...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 66.0.3359.181, webStorageEnabled: true}
Session ID: bdf391bf16ddbda6c9f73d559404bae7
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:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
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:543)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100)
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.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
at com.sun.proxy.$Proxy17.sendKeys(Unknown Source)
at actions.PublishBroadcast.MediaLibAction.uploadImage(MediaLibAction.java:43)
at stepDefinitions.Publish.SDMediaLibrary.Upload_an_Image(SDMediaLibrary.java:43)
at ✽.When Upload an Image(features/publish/mediaLibrary/MediaLibrary.feature:11)
Error Log for Firefox:
org.openqa.selenium.InvalidArgumentException: File not found: src/test/resources/testData/twt_Pic.jpg
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'nagarjunaMBP.local', ip: 'fe80:0:0:0:c2e:b816:67ae:922b%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 60.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 53177, moz:profile: /var/folders/g4/dylg4g7s7wb..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: MAC, platformName: MAC, platformVersion: 17.5.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 7c932de3-ea6a-a143-a7b4-bf7dfa3e2660
Project Structure:
- Project/src/main/java - Contains actions, UI element repository, Step Defenitions. From where the file is being called
- Project/src/test/java - Contains only runner class
- Project/src/test/resources/customLib - Contains drivers
- Project/src/test/resources/features - Contains feature files
- Project/src/test/resources/testData - Contains the test data including the file which i'm trying to call here.
Solution
You can try creating a File
instance and getting the absolute path from there.
File file = new File("src/test/resources/testData/twt_Pic.jpg");
yourElement.sendKeys(file.getAbsolutePath());
Answered By - iamkenos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.