org.openqa.selenium.InvalidSelectorException: Unsupported CSS selector '*[name='email_field']'. Reason: 'Error: 'name' is not a valid attribute

Viewed 38

I face that error while using @AndroidFindBy although when I try to find an element by the findElement function I didn't face that error despite using the same Xpath in the two cases, The error said that name isn't an attribute but I didn't use 'name' to identify element That is my loginscreenobject class where I identify the elements in that screen

public class LoginScreenObjects extends Base {
    public LoginScreenObjects()
    {   
        System.out.println("Cout"+driver);
        PageFactory.initElements(driver, this);
    }
    
    //identify the login screen elements
    @AndroidFindBy(xpath ="//android.widget.EditText[@text='Email']")
    private WebElement email_field;
    @AndroidFindBy(xpath="//android.widget.EditText[@text='Password']")
    private WebElement password_field;
    @AndroidFindBy(xpath="//android.widget.Button[@text='Sign in']")
    private WebElement login_btn;
    
    //identify the login screen functions
    
    //Function1:insert email and password
    public void fillemailAndpasword(String email,String Password) {
        email_field.sendKeys(email);
        password_field.sendKeys(Password);
    }
    //Function2:click on the login button
    public void click_on_loginbtn() {
        login_btn.click();
                
    }
    
    //Function3:Is login button enabled
        public boolean Is_logintn_enabled() {
            return login_btn.isEnabled();
                
    }
        
   //Function4:Clear Email field and password field
        public void ClearEmailAndPass() {
            email_field.clear();
            password_field.clear();
        }
    
    

}

And that is my testCase

public class LoginScreenTest extends Base {
    //Create an object from the LoginScreenObjects class
    LoginScreenObjects logscreen=new LoginScreenObjects();
    @Test
    public void Tc_01()
    {
        logscreen.fillemailAndpasword("m8@sbs.com", "536860574604");
        logscreen.click_on_loginbtn();
    }

}

And that is the error that appear when I run my testcase

org.openqa.selenium.InvalidSelectorException: Unsupported CSS selector '*[name='email_field']'. Reason: 'Error: 'name' is not a valid attribute. Supported attributes are 'checkable, checked, clickable, enabled, focusable, focused, long-clickable, scrollable, selected, index, instance, description, resource-id, text, class-name, package-name''
For documentation on this error, please visit: https://selenium.dev/exceptions/#invalid_selector_exception
Build info: version: '4.4.0', revision: 'e5c75ed026a'
System info: host: 'DESKTOP-MCJ49E3', ip: '192.168.1.9', os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.3'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [95e7ce18-995d-404e-8eea-3a3b038afc7a, findElement {using=css selector, value=*[name='email_field']}]
Capabilities {appium:appActivity: sbs.softpos.ui.activities.S..., appium:appPackage: sbs.softpos.edfaa, appium:appWaitForLaunch: false, appium:automationName: UiAutomator2, appium:databaseEnabled: false, appium:desired: {appActivity: sbs.softpos.ui.activities.S..., appPackage: sbs.softpos.edfaa, appWaitForLaunch: false, automationName: UiAutomator2, deviceName: Galaxy A22, platformName: android}, appium:deviceApiLevel: 31, appium:deviceManufacturer: samsung, appium:deviceModel: SM-A225F, appium:deviceName: R58RC2C6YQF, appium:deviceScreenDensity: 300, appium:deviceScreenSize: 720x1600, appium:deviceUDID: R58RC2C6YQF, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:pixelRatio: 1.875, appium:platformVersion: 12, appium:statBarHeight: 53, appium:takesScreenshot: true, appium:viewportRect: {height: 1399, left: 0, top: 53, width: 720}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID}
Session ID: 95e7ce18-995d-404e-8eea-3a3b038afc7a
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    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 io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:180)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547)
    at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:162)
    at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:60)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:365)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:357)
    at org.openqa.selenium.By$PreW3CLocator.findElement(By.java:429)
    at org.openqa.selenium.By$ByName.findElement(By.java:238)
    at org.openqa.selenium.support.ByIdOrName.findElement(ByIdOrName.java:50)
    at org.openqa.selenium.remote.ElementLocation$ElementFinder$1.findElement(ElementLocation.java:136)
    at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:80)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:365)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:357)
    at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:70)
    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:39)
    at jdk.proxy2/jdk.proxy2.$Proxy13.sendKeys(Unknown Source)
    at com.EdfaPay.Screens.LoginScreenObjects.fillemailAndpasword(LoginScreenObjects.java:29)
    at testScenarios.LoginScreenTest.Tc_01(LoginScreenTest.java:14)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.testng.TestRunner.privateRun(TestRunner.java:794)
    at org.testng.TestRunner.run(TestRunner.java:596)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
    at org.testng.SuiteRunner.run(SuiteRunner.java:276)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
    at org.testng.TestNG.runSuites(TestNG.java:1063)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

0 Answers
Related