5

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.

Sukumar MS
  • 748
  • 1
  • 11
  • 42

3 Answers3

2

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
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • hey mr Andersson can u say how to set setWebContentsDebuggingEnabled to true in ionic framework.to switch to web_view – Sukumar MS Dec 23 '16 at 09:51
  • Sorry, have no idea about how `ionic` framework works :( `css selector` for your button could be `button.button.button-raised-button-balanced.ink-dark.button-block` – Andersson Dec 23 '16 at 09:54
2

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

Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77
1

just try to apply 10 seconds wait [Thread.sleep(10000);] before you are performing the operation on this button. if it works then fine otherwise change the locator to cssSelector.