1

I don't understand why I get this error : Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument for click action

package day18;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;



public class UploadFileOrange {

    public static void main(String[] args) throws InterruptedException, FindFailed {
        
        System.setProperty("webdriver.chrome.driver","C://Drivers//chromedriver_win32/chromedriver.exe" );
        WebDriver driver = new ChromeDriver();
        
        driver.get("https://opensource-demo.orangehrmlive.com/");
        driver.manage().window().maximize();
        
        driver.findElement(By.xpath("//*[@id=\"txtUsername\"]")).sendKeys("Admin");
        driver.findElement(By.xpath("//*[@id=\"txtPassword\"]")).sendKeys("admin123");
        driver.findElement(By.xpath("//*[@id=\"btnLogin\"]")).click();
        
        Thread.sleep(3000);
        
        WebElement PIM = driver.findElement(By.xpath("//*[@id=\"menu_pim_viewPimModule\"]"));
        WebElement AddEmp = driver.findElement(By.xpath("//*[@id=\"menu_pim_addEmployee\"]"));
        
        Actions act = new Actions(driver);
        
        act.moveToElement(PIM).moveToElement(AddEmp).click().build().perform();
        
        Thread.sleep(3000);
        
        driver.findElement(By.xpath("//*[@id=\"firstName\"]")).sendKeys("Fruit");
        driver.findElement(By.xpath("//*[@id=\"lastName\"]")).sendKeys("Fruit");
        
        Thread.sleep(3000);
        
        **driver.findElement(By.name("photofile")).click();** //IMAGE UPLOAD BUTTON
        
        Thread.sleep(3000);
        
        String ImageFilePath = "C:\\Users\\lu.ungaro\\Desktop\\Corso Automation - Selenium\\18";
        String InputFilePath = "C:\\Users\\lu.ungaro\\Desktop\\Corso Automation - Selenium\\18\\ClassExamples\\ClassExamples\\FileUpload using Sikuli\\Fruites\\inputfiles";
        
        Screen s = new Screen();
        
        Pattern fileInputTextBox = new Pattern(ImageFilePath + "box.PNG");
        Pattern openButton = new Pattern(ImageFilePath + "apri.PNG");
        
        Thread.sleep(3000);
        
        s.wait(fileInputTextBox, 20);
        s.type(fileInputTextBox,InputFilePath+"apple.jpg");
        s.click(openButton);
        
        
    
        
        

    }

}

When I run this code I get this exception:

Starting ChromeDriver 88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784}) on port 10403
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
gen 29, 2021 5:58:30 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument
  (Session info: chrome=88.0.4324.104)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'HEA23009', ip: '192.168.215.232', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '14.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 88.0.4324.104, chrome: {chromedriverVersion: 88.0.4324.96 (68dba2d8a0b14..., userDataDir: C:\Users\LU5787~1.UNG\AppDa...}, goog:chromeOptions: {debuggerAddress: localhost:62977}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 33ff537b7ce0eb56b57c2ce2f9025633
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    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:552)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
    at day18.UploadFileOrange.main(UploadFileOrange.java:44)

I'm tryng to use SIKULI to upload an image in a test website. I am using WebDriver to access the website and do a series of action to get to the upload image page.

The first click action (login) works but the code stops running when I try to execute click action on image upload button. I tried different locators but I always get this.

I dowloaded the latest version of ChromeDriver too.

But I cannot identify what is the problem

Thanks for helping

Luigi Ungaro
  • 11
  • 1
  • 6
  • Which is line **44**? – undetected Selenium Jan 29 '21 at 17:08
  • I would avoid those escapes... just use a single quote instead of \"... ex: By.xpath("//*[@id='txtUsername']") Btw, chances are you can just sendKeys() to the tag here and save yourself some typing...https://stackoverflow.com/questions/16896685/how-to-upload-file-using-selenium-webdriver-in-java?noredirect=1&lq=1 – pcalkins Jan 29 '21 at 23:43
  • line 44: **driver.findElement(By.name("photofile")).click();** //IMAGE UPLOAD BUTTON – Luigi Ungaro Feb 01 '21 at 09:33
  • @LuigiUngaro same issue, the exception message seems unhelpful – YouneL Nov 24 '21 at 16:53

1 Answers1

1

Please try JavaScript to perform the click option. Faced same error and got it resolved with below code

WebElement element = driver.findElement(By.id("photofile"));
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", element);