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");
I am unable to enter the mobile number in mobile number field
@Swapna_Das
can you try this?
driver.findElement(By.className(“android.widget.EditText”)).sendkeys(“9898989898”);
This is also not working. For mobile if I will use By.className(“android.widget.EditText”) locator, for password what class I will use?
@Swapna_Das
get(0) or get(1) with findElements
if after clicking in textbox keyboard is opening then you can try
driver.getKeyboard().sendKeys(“98989898”)
there is space b/w mobileno it’s wrriten as “Mobile No”.
have you tried with Android presskey codes?
WebElement mobileNo = driver.findElement(By.ClassName(“android.widget.EditText”)).get(0).sendkeys(“9898989898”);
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.
How an WebElement will accept sendKeys. It will give you error
give it try. and tell me the result.
WebElement inputField = driver.findElement(By.Locator("LocatorValue"));
inputField.sendKeys(Keys.TAB);
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
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’]
it’s perfect code. what’s problem?
you should switch element android to web will make easy.
Ayetri
June 10, 2019, 10:10am
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”);