This is my upload video function
public void uploadVideo(By locator, String path) {
WebElement chooseFile = driver.findElement(locator);
LocalFileDetector detector = new LocalFileDetector();
((RemoteWebElement) chooseFile).setFileDetector(detector);
chooseFile.sendKeys(path);
}
This is an error I am facing while executing, I'm using the above function in my selenium java cucumber framework. This used to work for selenium under the 4 version since we have upgraded to selenium 4 we are facing this issue.
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 100.0.4896.60, chrome: {chromedriverVersion: 100.0.4896.60 (6a5d10861ce8..., userDataDir: C:\Users\VISHAL~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:63997}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:63997/devtoo..., se:cdpVersion: 100.0.4896.60, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Element: [[ChromeDriver: chrome on WINDOWS (c01e213dd495b9b7c3c4ef3845499e4e)] -> xpath: //div[@class='uppy-Dashboard-AddFiles']/input[@class='uppy-Dashboard-input'][2]]
Session ID: c01e213dd495b9b7c3c4ef3845499e4e
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.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:251)
at org.openqa.selenium.remote.RemoteWebElement.upload(RemoteWebElement.java:117)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:104)
at com.cucumber.utilities.DriverActions.uploadVideo(DriverActions.java:1034)
at com.peopleGrove.pageActions.QnAPromptsPageActions.videoPromptCreatorPage_dragandUploadVideo(QnAPromptsPageActions.java:229)
at com.peopleGrove.stepDefinitions.QnAPromptsStepDefinitions.upload_the_pre_created_video_from_the_files(QnAPromptsStepDefinitions.java:224)
CodePudding user response:
This error message...
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 100.0.4896.60, chrome: {chromedriverVersion: 100.0.4896.60 (6a5d10861ce8..., userDataDir: C:\Users\VISHAL~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:63997}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:63997/devtoo..., se:cdpVersion: 100.0.4896.60, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Element: [[ChromeDriver: chrome on WINDOWS (c01e213dd495b9b7c3c4ef3845499e4e)] -> xpath: //div[@class='uppy-Dashboard-AddFiles']/input[@class='uppy-Dashboard-input'][2]]
...implies that though the element was identified yet chooseFile.sendKeys(path)
failed.
Solution
Wait for the <input>
element to be clickable before you attempt to send the file as follows:
public void uploadVideo(By locator, String path) {
WebElement chooseFile = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(locator));
LocalFileDetector detector = new LocalFileDetector();
((RemoteWebElement) chooseFile).setFileDetector(detector);
chooseFile.sendKeys(path);
}
CodePudding user response:
This worked !!!!
public void uploadVideo(By locator, String path) throws InterruptedException {
Thread.sleep(2000);
WebElement chooseFile = driver.findElement(locator);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].style.display='block';", chooseFile);
chooseFile.sendKeys(path);
}