How to locate the allow button tried by using class and name locators but getting error
Hey Dhananjay…
I can easly find b Locators of Allow/Deny by UIAutomator.
I’ve encountered the same problem while allowing device to access the location. What i did is …stored the Allow button xpath in a list. Iterated the list and clicked on the Allow button. It worked fine for me.
Steps:
-
Store allow button locators in List as
@AndroidFindBys(value = @AndroidFindBy(id = AllowGPSPopUp_id))
public static List AllowGpsPopUp; -
write a method to click on Allow Button
public static void allowGpsAccess(List list) throws Exception
{if(list.isEmpty()) { driver.findElement(By.className(somewebElementbehind popup)).click(); log.info("Allow GPS button is unavailable"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } else{ driver.findElement(By.id(AllowGPSPopUp_id)).click(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
-
Call the method by passing the list as:
allowGpsAccess(AllowGpsPopUp);
It will work for sure.
how to store the “allow” button locators in list??? please clarify step by step so tht it will be useful
@dhananjay maybe better grant all permission to app with driver start?
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, "true");
after ussing this capability in program ,i am getting this message: AUTO_GRANT_PERMISSIONS cannot be resolved or is not a field.
so what to do now ?
@dhananjay switch to latest java-client and add:
import io.appium.java_client.remote.*;
added the latest java client jar 5.0.2 still it is showing red line on AUTO_GRANT_PERMISSIONS
@dhananjay you can:
// add direct import
import io.appium.java_client.remote.AndroidMobileCapabilityType;
// or
capabilities.setCapability("autoGrantPermissions", "true");
added directly ,now after executing program getting this error:
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: com.directory.scgt/.Activity.SplashScreenActivity never started. Current: com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
need to share my entire program ???
thanks for your prompt reply
@dhananjay do you still see permission dialog? your appium server version is?
no not nw.
appium version is : 1.4.16.1
@dhananjay aaaaa. update Appium at least to 1.6.5 but better to 1.7.0. 1.4.16.1 - does not know grandPermissions
how to update??
by using npm install appium 1.6.5 command???
use:
npm uninstall -g appium
npm install -g appium // for latest official release
npm install -g [email protected] // for some version
npm install -g appium@beta // for leatest beta
successfully updated the appium version still getting same error:
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: com.directory.scgt/.Activity.SplashScreenActivity never started. Current: com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
@dhananjay pls share appium logs in debug mode
According to error you still see permissions.
@dhananjay no.
- set debug logs!
appium --log-level debug
- copy your logs into https://gist.github.com/ and share link