I am new to appium and im trying to figure how to check if a text is present in the page of my app.
I am automating iOS app and got the xpath with appium inspector.
Kindly help me no other forums were helpfull for me.
Hi Syed,
You can use isDisplayed() method.
example.:
if(driver.findElement(By.xpath(“YOUR XPATH”)).isDisplayed() )
{
/*Do this/
}
else
{
/*Do this/
}
Thanks for that. It did work for me.
But what if i have to extract the text from the xpath and compare with the expected text?
can you help me ?
@Syed_Umar : Use getAttribute(“text”)
Webelement element = driver.findElement(By.xpath(“YOUR-XPATH)”) ;
element.getAttribute(“text”);
I use the below method to check if element is present or not
protected boolean isElementPresent(By by) throws IOException {
boolean isElement = false;
try
{
if (driver.findElement(by) != null)
{
isElement = true;
return isElement;
}
}
catch(Exception e)
{
System.out.println(e);
System.out.println(“Element not found”);
isElement = false;
return isElement;
}
return isElement;
}