Unable to enter sendkeys value in android automation


#1

AndroidDriver driver;
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.DEVICE_NAME, “W89DN7UGWWPBHUJZ”);
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, “7.0”);
caps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, “com.commutec.operatorapplication”);
caps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, “com.commutec.operatorapplication.MainActivity”);

    driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
    Thread.sleep(2000);
    WebElement mobileNo = driver.findElement(By.xpath("//android.widget.EditText[@text='Mobile No']"));
    mobileNo.click();
    mobileNo.sendKeys("9999999999");


#2

I am unable to enter the mobile number in mobile number field


#3

@Swapna_Das

can you try this?
driver.findElement(By.className(“android.widget.EditText”)).sendkeys(“9898989898”);


#4

This is also not working. For mobile if I will use By.className(“android.widget.EditText”) locator, for password what class I will use?


#5

@Swapna_Das
get(0) or get(1) with findElements


#6

if after clicking in textbox keyboard is opening then you can try
driver.getKeyboard().sendKeys(“98989898”)


#7

This is also not working


#8

there is space b/w mobileno it’s wrriten as “Mobile No”.


#9

I have written same also


#10

have you tried with Android presskey codes?


#11

WebElement mobileNo = driver.findElement(By.ClassName(“android.widget.EditText”)).get(0).sendkeys(“9898989898”);


#12

make sure there is no other element with same classname or above mobile no. if there is element with same class name and its before mobile no than change 0 according to it. here 0 = 1.


#13

How an WebElement will accept sendKeys. It will give you error


#14

give it try. and tell me the result.

WebElement inputField = driver.findElement(By.Locator("LocatorValue"));
inputField.sendKeys(Keys.TAB);

#15

Actually I had not applied
caps.setCapability(“unicodeKeyboard”, “true”);
caps.setCapability(“resetKeyboard”, “true”);

So that it was not entering the values. But now I can able to put the values and the values are showing like e.g Mobile No999999999.
But I want the output should be 999999999


#16

please show me code.


#17

AndroidDriver driver;

    // Load the properties File
    Properties props = new Properties();
    FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") + "//application.properties");
    props.load(objfile);

    DesiredCapabilities caps = new DesiredCapabilities();

    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "0123456789ABCDEF");
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.2.2");
    caps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.commutec.operatorapplication");
    caps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.commutec.operatorapplication.MainActivity");
    caps.setCapability("unicodeKeyboard", "true");
    caps.setCapability("resetKeyboard", "true");

    driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
    Thread.sleep(300);
    driver.findElement(By.xpath(props.getProperty("mobileNo"))).sendKeys("9999999999");
    Thread.sleep(500);
    driver.findElement(By.xpath(props.getProperty("password"))).sendKeys("12345");

//application.properties
mobileNo=//android.widget.EditText[@text=‘1’]
password=//android.widget.EditText[@text=‘2’]
signIn=//android.widget.Button[@text=‘SIGN IN’]


#18

it’s perfect code. what’s problem?


#19

you should switch element android to web will make easy.


#20

driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), caps);
Thread.sleep(2000);
driver.findElement(By.xpath("//android.widget.TextView[contains(@text=‘Mobile No’]")).sendkeys(“9999999999”);