In my Objet Repository when I use this Xpath :
//*[
@class
= ‘android.widget.TextView’ and (text() = ’ N°2015020397000007 ’ or . = ’ N°2015020397000007 ')]
Katalon find my object.
If I replace it by :
//*[
@class
= ‘android.widget.TextView’ and (contains(text(),‘N°2015020397000007’))]
it doesn’t find it anymore.
I don’t understand why ??
In fact I need to identify my object only with ‘N°’ so I wanted to use something like :
//*[
@class
= ‘android.widget.TextView’ and (contains(text(),‘N°’))]
Thank You !!
Other question :
My path for the object I’m looking for (detected by mobile Object Spy) is :
//hierarchy/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/
android.widget.TextView[11]
How can I easily loop in all the last TextView ? without this absolute path ??
I need to check for specific “text” value for all the TextView[1] / TextView[2] / TextView[3] … / TextView[11] in bold above !
Thanks for your help
(I use Katalon Studio for a mobile application)
In my Objet Repository when I use this Xpath :
//*[
@class
= ‘android.widget.TextView’ and (text() = ’ N°2015020397000007 ’ or . = ’ N°2015020397000007 ')]
Katalon find my object.
If I replace it by :
//*[
@class
= ‘android.widget.TextView’ and (contains(text(),‘N°2015020397000007’))]
it doesn’t find it anymore.
I don’t understand why ??
In fact I need to identify my object only with ‘N°’ so I wanted to use something like :
//*[
@class
= ‘android.widget.TextView’ and (contains(text(),‘N°’))]
You should change text() to
.
. For more explanations, please read this post:
xml - XPath contains(text(),'some string') doesn't work when used with node with more than one Text subnode - Stack Overflow
Other question :
My path for the object I’m looking for (detected by mobile Object Spy) is :
//hierarchy/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/
android.widget.TextView[11]
How can I easily loop in all the last TextView ? without this absolute path ??
I need to check for specific “text” value for all the TextView[1] / TextView[2] / TextView[3] … / TextView[11] in bold above !
You can use AppiumDriver.findElements() to find all elements that match the same locator.
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver
AppiumDriver driver = MobileDriverFactory.getDriver()
List elements = driver.findElements(By.xpath("//hierarchy/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.TextView"))
for (WebElement e in elements) {
println e.getText()
findElements(By.xpath(“…/android.widget.LinearLayout[1]/android.widget.TextView”)) will return all TextView elements under the LinearLayout parent
Can contains text use it for application?
String xpath = “//android.widget.TextView[text()[contains(.,‘TMR2VAG4’)]]”,
xpath1 = “//*[@class = ‘android.widget.TextView’ and (contains(., ‘TMR2VAG4’))]”
AppiumDriver driver = MobileDriverFactory.getDriver()
driver.getPageSource()
List elements = driver.findElements(By.xpath(xpath))
Mobile.comment("number obj: " + elements.size())
I tried with xpath and xpath1 but no objects were found
Where am I wrong and how can I use contains text on mobile application ?