I'm using Appium for Android
the following works for clicking on the element
driver.findElement(By.xpath("//*[@resource-id='com.app.android:id/prelogin_signup']")).click();
But I am trying to check if an element is on the screen and I tried the following
if (driver.findElement(By.xpath("//*[@resource-id='com.app.android:id/prelogin_signup']")).isDisplayed()) {
System.out.println("FOUND");
} else {
System.out.println("NOT FOUND!");
}
but it returns an Exception saying
INFO: HTTP Status: '405' -> incorrect JSON status mapping for 'unknown error' (500 expected)
org.openqa.selenium.WebDriverException: Method is not implemented
How can I check to see if an element is on the screen?
You can try this, hope it helps
//If the element found, do as you want
if (driver.findElements(By.xpath("//*[@resource-id='com.app.android:id/prelogin_signup']")).size() > 0) {
System.out.println("FOUND");
} else {
System.out.println("NOT FOUND!");
}
you can surround your code with try catch block.
public boolean isElementDisplayed(){
try{
return driver.findElement(By.xpath("//*[@resource-id='com.app.android:id/prelogin_signup']")).isDisplayed();
}catch(Exception e){
//System.out.println(e);
return false;
}
}
you can also make the generic function to check if element is displayed.
public boolean isElementDisplayed(MobileElement element){
try{
return element.isDisplayed();
}catch(Exception e){
//System.out.println(e);
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With