This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 11
Jul 2018

When i check if element exist on screen like this :

if(driver.findElement(By.name(“OK”)).isEnabled())

I get an error message :

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 37 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html6

I need to check is the element (popup message with “OK” button) exist

Thanks !

  • created

    Jul '18
  • last reply

    Jul '18
  • 10

    replies

  • 2.7k

    views

  • 5

    users

  • 2

    links

Same Error :frowning:

An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)

This is the line :slight_smile:

if(driver.findElement(By.name(“Allow”)).isDisplayed() )
telemessage.general.tapMessageButtonByName(“Allow”);

Thanks !!

  1. Check manually first in attributes if visible is shown as true
  2. if yes then use… element.getAttribute(“Visible”) which will return the boolean value assigned to the element present in the screen

By Name is depreciated in latest Appium.
If you want to verify the String try it this way:

if(driver.findElement(By.xpath ("//*[@text=‘Allow’]").isDisplayed() )

Hope it works for you.

Cheers!

isDisplayed() for me will throw org.openqa.selenium.NoSuchElementException: Can’t locate an element by this strategy:… if the element is not present in the page.
I can only use it in assertion to validate it.
If I want to check if the element is not present and then continue the test I’m using this work around found here

public void checkIfElementIsPresent(MobileElement element1) {
WebDriverWait wait = new WebDriverWait(driver, 1);
try {
if (wait.until(ExpectedConditions.visibilityOf(element1)) != null) {
Assert.assertTrue(element1.isDisplayed());
//do something if present

		}
	} catch (Exception e) {
		log.info("Element not present, we are good here!");
                    //do something if not present
		// Assert.assertTrue(element2.isDisplayed());
	}
}

Great, I’ll try it

A small questions… can you please write me an example here how do you create an MobileElements ?

if i use this to click on Element with xPath :

driver.findElement(By.xpath("//XCUIElementTypeButton[@name=“Next”]")).click();

What will be my MobileElement ?

thanks !!!1

Well, my framework is with POM(Page Object Model)
I create the element in other class called Screens like this:
@AndroidFindBy(id = “dialog_later_button”)
public MobileElement laterButtonOverlay;

In your case you can do like this:
WebDriverWait wait = new WebDriverWait(driver, 1);
try {
if (wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathExpression) != null) {
//not mandatory this like
Assert.assertTrue(driver.findElement(By.xpath ("//*[@text=‘Allow’]").isDisplayed());
//do something if present

		}
	} catch (Exception e) {
		log.info("Element not present, we are good here!");
                    //do something if not present
		}
}