Can not proceed when element is not finded


#1

Hi all,

Im trying to find an element, that i know, that is not in the screen, and i want appium to continue with the code.

I’ve tried with the following code:

try:
driver.find_element_by_id(“android:id/button1”)
except:
print(‘Not finded’)

And the program is not getting out of the driver.find, it’s like a loop, how can i continue with the code?


#2

I’m using something like this:
/*
* Use this method to check if an element is not present If the element is
* present in the page source, test will fail, if element is not present, test
* will continue
*/

public void validateElementIsNotPresent(MobileElement element1) {
	WebDriverWait wait = new WebDriverWait(driver, 1, 100);
	try {
		if (wait.until(ExpectedConditions.visibilityOf(element1)) != null) {
			Assert.assertFalse(element1.isDisplayed());
		}
	} catch (Exception e) {
		log.info("Element not present, we are good here!");
		log.debug(e);
	}
}

#3

Hi,

Thanks for your answer, i can do it on python language?


#4

Just adapt to the python syntax, the logic should remain the same.
I don’t know python.