(Root cause: Object Object Repository/test/mytext not found)


#1

Hi,
Good Day!!!

I’m trying to get text using gettext but getting error (Root cause: Object Object Repository/test/mytext not found)…

Note: The mytext object is in the object Repository/test/mytext

Can anyone help me with this?


#2

Hi Mandy,

Would you be able to share your test code? Could you also share a screenshot of what properties the mytext object has from the repository (double clicking it should open it)?

Thanks,

Chris


#3

also share full log text so we can see exact messages


#4

Chris Trevarthen said:

Hi Mandy,

Would you be able to share your test code? Could you also share a screenshot of what properties the mytext object has from the repository (double clicking it should open it)?

Thanks,

Chris

Hi Chris,

Here are the attachments below,

and in between can you help me with the Xpath,

I have googled for Xpath but they haven’t explained me how to use them in Katalon Mobile Testing.

Can you explain me how to define this “mytext” using Xpath.
.

Thanks!!!

image.png

logViewer.txt

properties.PNG


#5

Hi Mandy,

Thanks for providing all of that info.

It has been my experience that when I receive an error saying that an object can’t be found, it really cannot be found on the screen, sometimes because it’s hidden by another view or I haven’t given it enough time to show up.

From the initial glance, it looks like your test is set up correctly. One thing you might want to try doing is to put a delay after you tap the Login button:

Mobile.delay(5)

Just to make sure that you’re not looking for the text before it shows on the screen. You can also change the last parameter (currently set to 0) on your Mobile function calls to be a number of seconds to wait.

A way to double check that the element actual is showing on the screen is to add some logging to print out the contents of the screen right before you do your getText() call. You should be able to do that by putting the following import statements at the top of your test case:

import com.kms.katalon.core.logging.KeywordLoggerimport com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactoryimport io.appium.java_client.AppiumDriver

Then in the code for your test, add the following right before the getText() call:

AppiumDriver<?> driver = MobileDriverFactory.getDriver()
KeywordLogger log = new KeywordLogger()
log.logInfo(driver.getPageSource())

When the test runs, you should see an entry in the Log Viewer for “Statement - log.logInfo(driver.getPageSource())” that shows the start of the XML for the screen. If you tap on it, you’ll see all of the XML for the screen on the right-hand pane. If you could copy and share that, I can help troubleshoot why the getText() isn’t working. (I recommend putting it into a text editor first to remove any sensitive data, like package names, etc.)

Hope this helps,

Chris


#6

As for how to define the xpath, if you’re not familiar with what an xpath is, then you can find out some more on the MSDN site:

https://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx

If you already know about xpaths, then you can create test objects using xpath by editing the object’s properties (using the screen you pasted above). Check the box for “Detect object” in the row for the “xpath” property (unchecking the other boxes). Paste in your object’s xpath in the “Value” column.

NOTE: Katalon Studio and its underlying tools will only support xpath version 1.0, so you might be restricted in some of the built-in xpath functions you can use.

ALSO NOTE: There is a radio button at the top of the object properties screen for “Selection method” and there is a value for “XPath” - I don’t think this works, so I would rely on the “Attributes” selection.

Hope this helps,

Chris


#7

Chris Trevarthen said:

Hi Mandy,

Thanks for providing all of that info.

It has been my experience that when I receive an error saying that an object can’t be found, it really cannot be found on the screen, sometimes because it’s hidden by another view or I haven’t given it enough time to show up.

From the initial glance, it looks like your test is set up correctly. One thing you might want to try doing is to put a delay after you tap the Login button:

Mobile.delay(5)

Just to make sure that you’re not looking for the text before it shows on the screen. You can also change the last parameter (currently set to 0) on your Mobile function calls to be a number of seconds to wait.

A way to double check that the element actual is showing on the screen is to add some logging to print out the contents of the screen right before you do your getText() call. You should be able to do that by putting the following import statements at the top of your test case:

import com.kms.katalon.core.logging.KeywordLoggerimport com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactoryimport io.appium.java_client.AppiumDriver

Then in the code for your test, add the following right before the getText() call:

AppiumDriver<?> driver = MobileDriverFactory.getDriver()

KeywordLogger log = new KeywordLogger()
log.logInfo(driver.getPageSource())


When the test runs, you should see an entry in the Log Viewer for _"Statement - log.logInfo(driver.getPageSource())"_ that shows the start of the XML for the screen. If you tap on it, you'll see all of the XML for the screen on the right-hand pane. If you could copy and share that, I can help troubleshoot why the getText() isn't working. (I recommend putting it into a text editor first to remove any sensitive data, like package names, etc.)

[![](https://s3.amazonaws.com/katalon-forum/editor/c8/gue4ko27dzdp.png)](https://s3.amazonaws.com/katalon-forum/editor/c8/gue4ko27dzdp.png)

  
  
Hope this helps,  
  
Chris  
  
  
  
  

  

Hi Chris,

I have checked with the same :

  1. Mobile.delay(10) => it didn’t work in my case.

  2. Adding the code before gettext() also not worked for my case and i haven’t got any xml. :frowning:

I have checked with other apk i got the message printed but i am not able to crack with my apk.
please refer to screen record (Other demo apk vs my tesing apk)

For demo apk :

  1. I am able to capture all the objects on the screen by selecting the objects in Mobile view and also in Katalon object spy.

With my test apk :

  1. I am able to capture the objects only using Katalon object spy but was unable to select from mobile view.

I think its little confusing please refer video in below link :

Thanks!!!

1.PNG

2.PNG

console.txt


#8

Hi Mandy,

That’s weird that it’s not logging the screen contents for you. Could you try changing the log.logInfo part to log.logWarning just in case your log file settings are to ignore “info” statements?

Chris


#9

Chris Trevarthen said:

Hi Mandy,

That’s weird that it’s not logging the screen contents for you. Could you try changing the log.logInfo part to log.logWarning just in case your log file settings are to ignore “info” statements?

Chris

Hi Chris,

I have changed to log.logwarning but still no luck :frowning:

34.PNG


#10

Hi Chris,

i was trying to get the text form the object using Xpath
i’m not sure if am doing it right way or wrong :frowning:

Please help me with this
Below are the images of code,object properties and Object Repository tree structure.

Thanks!!!

36.PNG

37.PNG

38e.PNG


#11

Hi Mandy,

For detecting the object by xpath, you should uncheck all of the other lines except for “xpath”. Then double-click on the value for xpath (in your screenshot, it’s currently “//hierarchy/android.width.FrameLayout[1]…”. You’ll want to enter a less brittle xpath instead, so something like:

//*[@class = 'android.widget.TextView' and @text = 'Username or password is incorrect.']

Behind the scenes, Katalon Studio will create an xpath based on the properties you have selected with “Detect object”. You only really need to make your own if you need a lot more control over the object detection or if you need to create the xpath programmatically.

- Chris


#12

Hi Chris,

I tried to get text using xpath but it shows Object is null, I’m not getting and not sure i’m doing it completely wrong or missing something.

This is the code i tried

def errormessage = Mobile.getText(findTestObject('/hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.TextView[2]'), 0)println(errormessage)def errormessagetext = Mobile.verifyMatch(errormessage, 'Incorrect email or password.', false)println(errormessagetext)

This the thing i got in console.

[35m[HTTP]e[39m e[37m-->e[39m e[37mGETe[39m e[37m/wd/hub/session/cd3356df-f7f3-4cae-a036-e897cdeb19b5/screenshote[39me[35m[HTTP]e[39m e[90m{}e[39m10-16-2018 04:01:15 PM - [FAILED] - Failed to get text from element (Root cause: java.lang.IllegalArgumentException: Object is null)10-16-2018 04:01:15 PM - [END]    - End action : Statement - errormessage = com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.getText(com.kms.katalon.core.testobject.ObjectRepository.findTestObject(/hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.TextView[2]), 0)10-16-2018 04:01:15 PM - [FAILED] - Test Cases/hogaarV2/hogarV2 FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Failed to get text from element (Root cause: java.lang.IllegalArgumentException: Object is null)	at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)


#13

Hi Mandy,

Just to give some more background, you can use the xpath to find an object in a few ways:

Using Mobile Recorder/Spy Mobile

You can use the Mobile Recorder/Spy Mobile to save/export a new Test Object in the Object Repository:

https://docs.katalon.com/display/KD/Spy+Mobile+Utility

You can then double-click that Test Object to edit the properties. Edit the Attributes to uncheck everything except the xpath:

Creating New Test Object in Object Repository

Alternatively, you can create a new Test Object in the Object Repository, giving it the “xpath” Name, “equals” Condition, and pasting in the Value of the xpath you want:

https://docs.katalon.com/display/KD/Manage+Test+Object

Creating New Test Object in Code

Finally, if you’d like to find an object by xpath in code, you can do the following:

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
TestObject myNewObject = new TestObject("TheObjectName")
myNewObject.addProperty("xpath", ConditionType.EQUALS, "//html/body")

So in your example above, you’d need to do something like:

def errorMsgObject = new TestObject()
errorMsgObject.addProperty("xpath", ConditionType.EQUALS, "/hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.TextView[2]")
def errormessage = Mobile.getText(errorMsgObject, 0)println(errormessage)def errormessagetext = Mobile.verifyMatch(errormessage, 'Incorrect email or password.', false)println(errormessagetext)

Or perhaps, to simplify the xpath, you could change the 2nd line to be:

errorMsgObject.addProperty("xpath", ConditionType.EQUALS, "//*[@class='android.widget.TextView'][1]")

I hope this helps,

Chris


#14

Hi Chris,

This worked for me thanks,
:smiley:


#15

Chris Trevarthen said:

Hi Mandy,

Just to give some more background, you can use the xpath to find an object in a few ways:

Using Mobile Recorder/Spy Mobile

You can use the Mobile Recorder/Spy Mobile to save/export a new Test Object in the Object Repository:

https://docs.katalon.com/display/KD/Spy+Mobile+Utility

You can then double-click that Test Object to edit the properties. Edit the Attributes to uncheck everything except the xpath:

Creating New Test Object in Object Repository

Alternatively, you can create a new Test Object in the Object Repository, giving it the “xpath” Name, “equals” Condition, and pasting in the Value of the xpath you want:

https://docs.katalon.com/display/KD/Manage+Test+Object

Creating New Test Object in Code

Finally, if you’d like to find an object by xpath in code, you can do the following:

import com.kms.katalon.core.testobject.ConditionType

import com.kms.katalon.core.testobject.TestObject
TestObject myNewObject = new TestObject(“TheObjectName”)
myNewObject.addProperty(“xpath”, ConditionType.EQUALS, “//html/body”)


  

So in your example above, you'd need to do something like:

  

def errorMsgObject = new TestObject()
errorMsgObject.addProperty(“xpath”, ConditionType.EQUALS, “/hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.TextView[2]”)
def errormessage = Mobile.getText(errorMsgObject, 0)println(errormessage)def errormessagetext = Mobile.verifyMatch(errormessage, ‘Incorrect email or password.’, false)println(errormessagetext)


  

Or perhaps, to simplify the xpath, you could change the 2nd line to be:

  

errorMsgObject.addProperty(“xpath”, ConditionType.EQUALS, “//*[@class=‘android.widget.TextView’][1]”)


  
I hope this helps,  
  
Chris

  

Hi Chris,

This worked for me thanks,

Good Day!!!


#16

Hi, am getting the same error in Mobile Automation.

Failed to tap on element ‘Object Repository/Application/CallsObjects/PinCode’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Object Object Repository/Application/CallsObjects/PinCode not found) .

Attached object repository screenshot.


#17

Hi. I also encountered errors like you. Have you solved the problem? I look forward to receiving help