For the first issue, I am not able to find any built-in Keywords (Mobile) which deals with drop down list. For ex in an app: If you have ‘Select Country’ as drop down and you want to select ‘Canada’ in the list by using katalon. I had tried using both options 'SelectListItemByLabel’ and ‘SelectListItemByIndex’ but did not get success. Is there any way to handle this?
For the second issue, for ex in an app: If you have some 50 songs on the screen then you need to scroll to bottom to view all the songs. In this case, if I want to scroll to 35 th song and tap on it using katalon then how to do that? As I said earlier, I have tried using **ScrolltoText **but no success.
Can you please let me know how to deal with above scenarios.
When you say ‘I am not able’ from both of your issues, what are the really obstacles you are facing? The built-in keywords you use don’t work for your scenarios?
I have this problem also. My web page has several multi-select dropdown elements. None of the Katalon Select Option commands will work. There is no error reported, but nothing is selected in the fields in question. Using record and playback doesn’t work either: Katalon records the action as Select Option By Value; but playing back that action has no effect.
I found that Mobile.scrollToText(‘My Label’) didn’t work well on Android when the drop down list was longer than one screen. It would scroll a bit, then stop, never finding my required item.
To get around this, I had to extend Katalon by creating a Custom Keyword to handle scrolling - this relies on the AppiumDriver library (thanks to Nhi Dinh for the sample code):
Create a new keyword file:
package com.my.keywords.android
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver
class swiping {
AppiumDriver driver;
swiping() {
this.driver = MobileDriverFactory.getDriver()
}
private scrollEntireList() {
// very specific to android and the type of element that makes up your dropdowns
ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView")
TouchAction touchAction = new TouchAction(driver)
def bottomElement = listElement[listElement.size() - 1]
def topElement = listElement[0]
// Press and scroll from the last element in the list all the way to the top
touchAction.press(bottomElement).moveTo(topElement).release().perform();
}
@Keyword
def boolean scrollListToElementWithText(String elementText) {
boolean isElementFound = false;
while (isElementFound == false) {
// very specific to android and the type of element that makes up your dropdowns
ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView")
for (int i = 0; i<listElement.size(); i++) {
String textItem = listElement[i].getText()
if (textItem == elementText) {
isElementFound = true;
return true;
}
scrollEntireList()
}
}
}
}
Then in your test, you can use the Custom Keyword like:
Is anyone write function for ios with custom keywords? Because I can just click dropdown in my mobile like select country and can not reach list. So how can I select third option in the list? @Chris Trevarthen
Hi @Chris_Trevarthen
Got below issue after using the suggested code
java.lang.ArrayIndexOutOfBoundsException: Negative array index [-1] too large for array size 0
at com.my.keywords.android.swiping.scrollEntireList(CustomKey.groovy:40)
at com.my.keywords.android.swiping.scrollListToElementWithText(CustomKey.groovy:57)
at com.my.keywords.android.swiping.invokeMethod(CustomKey.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
I reformatted my original answer since it was a little hard to read.
It might be a little more clear now that the line driver.findElementsByClassName("android.widget.CheckedTextView") is looking for a specific type of element, CheckedTextView.
You’re getting that error because there are no elements of that class type on your screen.
You can update that part to look for the correct element type that you need, e.g. android.widget.TextView.
NOTE: You’ll need to make that change in 2 places.