Invalid argument: invalid locator

Hello,
I use Ubuntu 18.04. I have Appium 1.19.1 installed.
I run Appium with the command: appium --chromedriver-executable /usr/bin/chromedriver I found this command because I need to run ChromeDriver 83.0.4103.14 which I have installed (I don’t know how to update ChromeDriver inside Appium…).

I get this error:

Exception in thread “main” org.openqa.selenium.InvalidArgumentException: invalid argument: invalid locator
(Session info: chrome=83.0.4103.106)
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘myname-Vostro-3590’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘5.4.0-58-generic’, java.version: ‘11.0.9.1’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: /home/myname/IdeaProjects/Hy…, appPackage: com.androidsample.generalstore, automationName: uiautomator2, databaseEnabled: false, desired: {app: /home/dejan/IdeaProjects/Hy…, automationName: uiautomator2, deviceName: emulator-5554, newCommandTimeout: 14, platformName: android}, deviceApiLevel: 30, deviceManufacturer: Google, deviceModel: sdk_gphone_x86_arm, deviceName: emulator-5554, deviceScreenDensity: 440, deviceScreenSize: 1080x2220, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 14, pixelRatio: 2.75, platform: LINUX, platformName: Android, platformVersion: 11, statBarHeight: 66, takesScreenshot: true, viewportRect: {height: 2022, left: 0, top: 66, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 365730ab-dea8-45f6-841f-25d0333f9103
*** Element info: {Using=name, value=q}
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.newInstance(Constructor.java:490)
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 io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:404)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByName(DefaultGenericMobileDriver.java:117)
at io.appium.java_client.AppiumDriver.findElementByName(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByName(AndroidDriver.java:1)
at org.openqa.selenium.By$ByName.findElement(By.java:284)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:57)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at ecommerce_tc_5.main(ecommerce_tc_5.java:55)

Part of the code where expcetion heppens:

        WebElement checkbox = driver.findElement(By.className("android.widget.CheckBox"));
        TouchAction t = new TouchAction(driver);
        t.tap(tapOptions().withElement(element(checkbox))).perform();

        driver.findElement(By.id("com.androidsample.generalstore:id/btnProceed")).click();
        Thread.sleep(7000);
        Set<String> contexts = driver.getContextHandles();

        for (String contextName : contexts) {
            System.out.println(contextName);
        }
        driver.context("WEBVIEW_com.androidsample.generalstore");
        driver.findElement(By.name("q")).sendKeys("hello");
1 Like

If Chromedriver is the reason, let’s try this setup, it may help you out.

setCapability("chromeOptions", ImmutableMap.of("w3c", false));
3 Likes

@zcmgyu awesome, worked for me. Thank you.

getting same error:
org.openqa.selenium.InvalidArgumentException: invalid argument: invalid locator

after switching to webview

Tried setting --> setCapability(“chromeOptions”, ImmutableMap.of(“w3c”, false));
still issue

Tried this statement and it worked for me for Invalid argument error. Thank you