Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appium: An element could not be located using Xpath in android hybrid apps?

I trying to automate a hybrid app using the appium.i had developed my app using Ionic Framework. i had completed the total setup ready.then i tried to find the elements inspecting using firebug in Mozilla.i found the xpath of a particular button is //Button[text()='BROWSE MENU'].

but when i try to test it using appium it is unable to find it , my test got failed.

i tried some thing like this in my test

driver.findElement(By.xpath("//button[text()='BROWSE MENU']")).click();

this is the error i am getting on the console

FAILED: Loginforsample
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: 5.13 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

this is inspectorenter image description here

i didn't know where exactly i am going wrong. initially i tried WEB_VIEW to inspect in chrome then i noticed that ionic has an advantage of direct inspecting using ionic serve. so i simply shifted to that and again i got struct here. please help me guys to this issue for me.

thanks in advance.

like image 277
Sukumar MS Avatar asked Dec 22 '16 10:12

Sukumar MS


2 Answers

I use to have this problem so i have used cssSelector it's a good way for testing hybrid apps !

like image 98
Emna Ayadi Avatar answered Sep 27 '22 22:09

Emna Ayadi


Try to add Explicit wait to your code:

//driver.switchTo().frame("put_iframe_id_or_name_here");  //to switch to iframe
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[text()='BROWSE MENU']")));
element.click();
//driver.switchTo().defaultContent();  //to switch back if required
like image 37
Andersson Avatar answered Sep 28 '22 00:09

Andersson