How to Show Keyboard on Any Screen/Activity

Hello everyone, i just want to ask, how to show keyboard on any screen?
Even i dont want to type anything on a textfield.
I just want to show it up.
Thanks a lot before!

Hi Gradito,

As far as I know, there is no way to just open the keyboard during tests. You’ll need to first tap on a text entry field to get it to open.

Hope this helps,

Chris

Chris Trevarthen said:

Hi Gradito,

As far as I know, there is no way to just open the keyboard during tests. You’ll need to first tap on a text entry field to get it to open.

Hope this helps,

Chris

But theres something weird on the app that im testing on
The objects are somehow cannot detected (while recording or object spy) on katalon.
I have 2 scenarios that little tricky to use
1. I hv to move to the next activity (manually using my finger tap tap) and back again and the object will be detected. (This scenario cannot be use for run the test case, only for capture object)
2. I tap the textfield manually (by my finger) and the keyboard shown up, and then i press back button (so the keyboard hide) and i try to capture the objects again, yap they were perfectly captured.

Note:
I already try to use tapAtPosition(x,y) and take the coordinates exactly on a textfield, but idk why the keyboard doesnt show up.

Hi Gradito,

That sounds weird indeed. Could you share a screenshot of the “All Objects” section of the Mobile Spy tool on the screen where you said you can’t detect the text fields?

Thanks,

Chris

Chris Trevarthen said:

Hi Gradito,

That sounds weird indeed. Could you share a screenshot of the “All Objects” section of the Mobile Spy tool on the screen where you said you can’t detect the text fields?

Thanks,

Chris

Thanks Chris, but i had a problem with my phone.
Tomorrow i will give you the screenshot of them, so we can analyze it then.

Chris Trevarthen said:

Hi Gradito,

That sounds weird indeed. Could you share a screenshot of the “All Objects” section of the Mobile Spy tool on the screen where you said you can’t detect the text fields?

Thanks,

Chris

Hello Chris, here we go again with the objects u requested before

This one is the UI that i captured, it seems the objects hid from something, we cant see the textfield captured
https://drive.google.com/file/d/10TGuaBM5WoiGiNhCiAKKjGzyoldnAiBl/view?usp=sharing

Another one, those objects were captured after i tap the textfield manually and the keyboard shown up, and i press back button the keyboard will hide, and i try to capture again. All of the objects captured perfectly
https://drive.google.com/open?id=1tOJ6vSuqV79UQlDabMvGKS1Cn9AzSlul

So how do you think bro?

Chris Trevarthen said:

Hi Gradito,

That sounds weird indeed. Could you share a screenshot of the “All Objects” section of the Mobile Spy tool on the screen where you said you can’t detect the text fields?

Thanks,

Chris

Hey chris?
Any updates?

Please help chris.

Hi Gradito,

That is very weird. I tried emulating your device using Android Studio and I am not seeing the issue that you’re seeing. Could you try using an emulated device instead of a real one and see if it gives you the same issue? You could do this in Android Studio->Tools->AVD Manager.

The only other thing I can think of is if for some reason there is an invisible view covering the input fields that doesn’t go away until you tap on one of the text fields, opening the keyboard. Does this happen on every screen with input fields or just this one?

- Chris

Chris Trevarthen said:

Hi Gradito,

That is very weird. I tried emulating your device using Android Studio and I am not seeing the issue that you’re seeing. Could you try using an emulated device instead of a real one and see if it gives you the same issue? You could do this in Android Studio->Tools->AVD Manager.

The only other thing I can think of is if for some reason there is an invisible view covering the input fields that doesn’t go away until you tap on one of the text fields, opening the keyboard. Does this happen on every screen with input fields or just this one?

- Chris

I cannot use any virtual device bcause the app is needed to run with real device
It detects sim card and it has to be connected to the intranet of my company.
So, any other suggestions?

Note:
I will delete the images ive shown before.

Chris Trevarthen said:

Hi Gradito,

That is very weird. I tried emulating your device using Android Studio and I am not seeing the issue that you’re seeing. Could you try using an emulated device instead of a real one and see if it gives you the same issue? You could do this in Android Studio->Tools->AVD Manager.

The only other thing I can think of is if for some reason there is an invisible view covering the input fields that doesn’t go away until you tap on one of the text fields, opening the keyboard. Does this happen on every screen with input fields or just this one?

- Chris

Chris, ive found how to force open keyboard
the code is:

((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

So any way to put native java android into katalon?
Should i do import something for the lib?

thanks a lot chris

Hi Gradito,

Looks like you figured out the issue is with hybrid apps - nice find! As for getting the keyboard to show with native Android code, I’ll have to look i to that, as I don’t know offhand.

-Chris

1 Like

Chris Trevarthen said:

Hi Gradito,

Looks like you figured out the issue is with hybrid apps - nice find! As for getting the keyboard to show with native Android code, I’ll have to look i to that, as I don’t know offhand.

-Chris

Alrite chris, hope this will fix on the next build. Hope a lot! hahaha
Thanks a lot anyway!

Chris Trevarthen said:

Hi Gradito,

Looks like you figured out the issue is with hybrid apps - nice find! As for getting the keyboard to show with native Android code, I’ll have to look i to that, as I don’t know offhand.

-Chris

Hello again Chris.

So what should i do then?
Is there any appium lib that i can import so the keyboard will show up…

Hi Gradito,

From what I can tell, we can’t execute the code you posted previously in Katalon Studio or Appium tests. I also looked into executing shell commands (via “adb” - Android Debug Bridge) in tests, and although we can do that, there doesn’t seem to be any command that will open the keyboard; only close it.

So, I think right now, we are left with tapping the text field on a screen to open the keyboard. You should be able to add this to your tests, which will find whatever the first text field is on the screen and tap it.

NOTE: This won’t work on screens where you don’t have any text fields (which makes sense, since the keyboard would probably not be helpful on those screens).

ALSO NOTE: This is for Android only, but you could change the xpath to support iOS.

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
TestObject firstTextField = new TestObject()
firstTextField.addProperty("xpath", ConditionType.EQUALS, "//*[@class='android.widget.EditText'][1]")
Mobile.tap(firstTextField, 1, FailureHandling.OPTIONAL)

If this is something you’re going to be doing in several tests, you could create that TestObject in the Object Repository with just the xpath set:

Then in your test, assuming the Object is named “First Text Field”:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
Mobile.tap(findTestObject('Object Repository/First Text Field'), 1, FailureHandling.OPTIONAL)

Hope this helps,

Chris

Screen Shot 2018-10-16 at 11.27.01 PM.png

Chris Trevarthen said:

Hi Gradito,

From what I can tell, we can’t execute the code you posted previously in Katalon Studio or Appium tests. I also looked into executing shell commands (via “adb” - Android Debug Bridge) in tests, and although we can do that, there doesn’t seem to be any command that will open the keyboard; only close it.

So, I think right now, we are left with tapping the text field on a screen to open the keyboard. You should be able to add this to your tests, which will find whatever the first text field is on the screen and tap it.

NOTE: This won’t work on screens where you don’t have any text fields (which makes sense, since the keyboard would probably not be helpful on those screens).

ALSO NOTE: This is for Android only, but you could change the xpath to support iOS.

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
TestObject firstTextField = new TestObject()
firstTextField.addProperty(“xpath”, ConditionType.EQUALS, “//*[@class=‘android.widget.EditText’][1]”)
Mobile.tap(firstTextField, 1, FailureHandling.OPTIONAL)


  

If this is something you're going to be doing in several tests, you could create that TestObject in the Object Repository with just the xpath set:

![](https://s3.amazonaws.com/katalon-forum/editor/py/16fgxr8srfj4.png)  

Then in your test, assuming the Object is named "First Text Field":

  
  
  
  
  
  
  
  

  
  
  
  
  
  
  
  

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
Mobile.tap(findTestObject(‘Object Repository/First Text Field’), 1, FailureHandling.OPTIONAL)


  
Hope this helps,  
  
Chris

  

Well chris! thanks for your help~

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
TestObject firstTextField = new TestObject()
firstTextField.addProperty("xpath", ConditionType.EQUALS, "//*[@class='android.widget.EditText'][1]")
Mobile.tap(firstTextField, 1, FailureHandling.OPTIONAL)

That code was works good
Is there any possibility to change it to Button? So the code will look like this:

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
TestObject firstButton = new TestObject()
firstButton.addProperty("xpath", ConditionType.EQUALS, "//*[@class='android.widget.Button'][1]")
Mobile.tap(firstButton, 1, FailureHandling.OPTIONAL)

So how bout that?

Hi, yes you can definitely tap on a button that way! That will find the first button on the screen and tap it.

Of course, it depends on what you’re trying to do with it, though, because as far as I know, tapping the button won’t open a keyboard on Android - only tapping a text field will do this.

- Chris

Chris Trevarthen said:

Hi, yes you can definitely tap on a button that way! That will find the first button on the screen and tap it.

Of course, it depends on what you’re trying to do with it, though, because as far as I know, tapping the button won’t open a keyboard on Android - only tapping a text field will do this.

- Chris

The problem has been solved bout to show up the keyboard Chris hahaha
now the button cannot be pressed, and undetected.
Hope with that code will solve my problem.