Unable to tap the link after tap on Allow button of permission alert in Appium?

北战南征 提交于 2020-01-06 06:35:47

问题


I'm automating an Android App using Appium. The issue I'm facing is it doesn't perform any action after tabbing on allow button of Contact Access Permission as shown in below Image :

I've tried below code for the same :

@Test
public void doLogin()
{

    driver.findElement(By.id("com.rawalinfocom.rcontact:id/text_next")).click();
    // Clicks on Allow Button
    driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button")).click();
    // Clicks on Skip link
    driver.findElement(By.id("com.rawalinfocom.rcontact:id/text_skip")).click();
    driver.findElement(By.id("com.rawalinfocom.rcontact:id/checkbox_terms_conditions")).click();
    driver.findElement(By.id("com.rawalinfocom.rcontact:id/button_get_started")).click();
    driver.findElement(By.id("com.rawalinfocom.rcontact:id/input_number")).sendKeys("9422307801");
    driver.findElement(By.id("com.rawalinfocom.rcontact:id/button_submit")).click();
    driver.findElement(By.id("com.rawalinfocom.rcontact:id/input_enter_password")).sendKeys("1234");
    driver.findElement(By.id("com.rawalinfocom.rcontact:id/button_login")).click();
    System.out.print("Login Success");
}

I'm newbie in Appium. How can I find the missing thing?


回答1:


In when pop ups like this comes the focus of driver is switched to that popup and is never returned after clicking, in such cases what you can do is keep "driver.getPageSource()" line right after clicking on that pop up and if it does not work in order to return the driver focus you can tap at some random location which will return the driver focus back to app

In order to tap at random position it will safe to tap at top position like (0,0) or (width/2,10) like that.

i tried tapping in one of the similar situation and it worked.




回答2:


I'm able to handle the popup by setting up below capabilities :

capabilities.setCapability("autoGrantPermissions", "true");
capabilities.setCapability("autoAcceptAlerts", "true");

In this case it doesn't show the popup the permission set always granted.




回答3:


Try using TouchAction class for tapping instead of click method. E.g.:

MobileElement skip = driver.findElement(By.id("com.rawalinfocom.rcontact:id/text_skip"));
TouchAction touch = new TouchAction (driver);
touch.tap (skip).perform ();

Also, I am assuming that you have used driver as AndroidDriver as illustrated below:

AndroidDriver <MobileElement> driver = new AndroidDriver (new URL ("http://<appium IP>:<Port>/wd/hub"), capabilities);

Hopefully this should work as it's working for me too.



来源:https://stackoverflow.com/questions/47434416/unable-to-tap-the-link-after-tap-on-allow-button-of-permission-alert-in-appium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!