2

enter image description hereI am trying to click on choose file button on my web application, but getting "Invalid argument " exception : Cannot click elements

1584522811772 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons

1584522811772 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry

1584522811772 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/

1584522811772 addons.webextension.screenshots@mozilla.org WARN Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*

JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.

1584522814417 Marionette INFO Listening on port 25414

1584522814453 Marionette WARN TLS certificate errors will be ignored for this session

Mar 18, 2020 2:43:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: W3C

Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Cannot click <input type=file> elements

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'

System info: host: 'RSOMWANSHI2L1', ip: '10.85.97.92', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_221'

Driver info: org.openqa.selenium.firefox.FirefoxDriver

Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 73.0,

WebDriver Code : package RealTimeExercise_E2E_Practise;

import java.io.IOException;

import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver;

public class FileUpload {

public static void main(String[] args) throws InterruptedException, IOException {
    System.setProperty("webdriver.gecko.driver","E:\\Practise\\Drivers\\geckodriver.exe");
    //System.setProperty("webdriver.chrome.driver", "E:\\\\\\\\Practise\\\\\\\\Drivers\\\\\\\\chromedriver.exe");
    //WebDriver driver = new ChromeDriver();
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();

    driver.get("https://i5130-win8.ptcnet.ptc.com:8443/InService/delivery/activation/activation.jsp");
    driver.findElement(By.xpath("//span[.='Use activation packet file']//parent::div//input[@type='radio']")).click();
    driver.findElement(By.xpath("//input[@type='file']")).click();      
    //driver.findElement(By.cssSelector("#file")).click();
    Thread.sleep(3000);
    //Runtime.getRuntime().exec("E:\\AutoItScript\\UploadFile.exe");


}

}

HTML :

File Path
  • pleease add the code and html – PDHide Mar 27 at 8:14
  • which line are you getting the error at / – PDHide Mar 27 at 9:38
  • @line : driver.findElement(By.xpath("//input[@type='file']")).click(); -Line 21 – rashmi somwanshi Mar 27 at 9:51
  • please add the html, and you have to click the button element and not the input element. May be click action is not supported for that particular input element. Find element "Button" and click on it – PDHide Mar 27 at 9:56
  • Actually its not button its input file only : – rashmi somwanshi Mar 27 at 10:29
1

Use browser actions,

Actions builder = new Actions(driver);

builder.moveToElement(driver.findElement(By.xpath("//input[@type='file']"))).click().build().perform();

The input element may not support the click action that's why you are getting the invalid argument error.

| improve this answer | |
  • Hey Thanks, it worked :) well.... – rashmi somwanshi Mar 29 at 13:36
  • @rashmisomwanshi could you upvote by clicking the up arrow icon near to my answerand accept the answer by clicking the tick sign near to my answer – PDHide Mar 29 at 13:37
  • 1
    done...Thank You – rashmi somwanshi Mar 30 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.