When I am opening the web app, I am getting a pop up. I'm trying to click on 'ALLOW' button in two ways:
caps.setCapability("autoGrantPermissions", true);
caps.setCapability("autoAcceptAlerts", true);
......
driver.switchTo().alert().accept();
nothing happens
driver.findElement(By.xpath("//android.widget.Button[@text='Allow']")).click();
I get an error:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
{"method":"xpath","selector":"//android.widget.Button[@text='Allow']"}
driver.findElement(By.id("android:id/button1")).click();
I get this error:
Returned value cannot be converted to WebElement: {message=no such element: Unable to locate element: {"method":"id","selector":"android:id/button1"}
This is my screenshot from UI Automator Viewer :
I found this post: Unable to tap the link after tap on Allow button of permission alert in Appium? but it didn't help me.
First: capabilities you were trying to use are for IOS only
On Android you have to find popup via findElement
and close them yourself.
Second: since you start Appium session for web application, before searching for native popups you must switch the context:
String webContext = driver.getContext();
Set<String> contexts = driver.getContextHandles();
for (String context: contexts){
if (context.contains("NATIVE_APP")){
driver.context(context);
break;
}
}
driver.findElement(By.id("android:id/button1")).click();
Don't forget to switch context back to web to continue:
driver.context(webContext);