【问题标题】:Unable To Find Locator After Giving Permission "com.android.packageinstaller:id/permission_allow_button" In Selenium Appium在 Selenium Appium 中授予“com.android.packageinstaller:id/permission_allow_button”权限后无法找到定位器
【发布时间】:2019-03-15 06:28:24
【问题描述】:

我正在使用 selenium Appium 自动化应用程序 硒更高版本 Appium 1.9.1

每当应用程序启动时总是弹出权限显示成功,我可以使用自动化点击权限,但在授予权限后,appium 无法在应用程序中找到元素。

如果我在应用程序中手动单击,例如,我单击下一步按钮并再次单击后退按钮,那么 appium 代码工作正常。

谁能帮助我如何在不进行手动交互的情况下运行我的脚本

Page class 

public class DriverSignUpPages {

    AndroidDriver<MobileElement> driver;
    public static final String packageName = "co.wapanda.android.beta";

    public DriverSignUpPages(WebDriver driver){
        this.driver = (AndroidDriver<MobileElement>)driver;
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
    }

    //-Storing element for pop up related access or permission 
    @AndroidFindBy(id = "com.android.packageinstaller:id/permission_allow_button")
    MobileElement permAlert;

    public void allowAccessLocation() {
        if(permAlert.isDisplayed()) {
            permAlert.click();
        } else {

        }
    }

    //-Store signUp locator and performed click action 
    @AndroidFindBy(id = packageName+":id/btn_signup")
    MobileElement signUpButton;

    public void clickOnSignUpButton() {
        signUpButton.click();
    }

    //-Store driversignup locator value and performed click action
    @AndroidFindBy(id = packageName+":id/btn_driver")
    MobileElement driverSignUp;

    public void clickOnDriverSignUp() {
        driverSignUp.click();
    }




------------------------------

Test case class 

public class ValidateDriverProcess {

    AppLaunch applaunch;
    DriverSignUpPages dprocess;
    AppiumDriver<MobileElement> driver;

    @BeforeMethod
    public void launchApplication( ) {
        applaunch = new AppLaunch();
        driver = (AppiumDriver<MobileElement>) applaunch.launchApplication();
    }

     @Test
    public void validateDriverSignupProcess() {
        try {
         DriverSignUpPages dprocess = new DriverSignUpPages(driver);
         Thread.sleep(5000);
         dprocess.allowAccessLocation();
         Thread.sleep(5000);
         dprocess.clickOnSignUpButton();
         Thread.sleep(5000);
         dprocess.clickOnDriverSignUp();
         Thread.sleep(5000);
         dprocess.enterSignUpDetail("test@abc.com", "9898989891", "123456");
         Thread.sleep(5000);
         dprocess.enterFirstAndLastNameInSignUp("Raj", "");
         Thread.sleep(5000);
         dprocess.enterVerificationCode("757575");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @AfterMethod
    public void closeApplication() {
        driver.quit();
    }


} 



------------

在appium日志中显示错误

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result
{"status":7,"value":"No element found"}

not able to find this line 
//-Store signUp locator and performed click action 
 @AndroidFindBy(id = packageName+":id/btn_signup")
 MobileElement signUpButton;

【问题讨论】:

  • 你试过 autoGrantPermissions=true 吗?
  • @AmitJain 不,我没有尝试使用 autoGrantPermissions= true ,因为我们需要使用权限警报来处理正负两种情况。如果我手动执行操作,那么自动化代码工作正常。
  • @AmitJain 出于测试目的,我添加了 autoGrandPermissions=true 但同样的问题再次出现。找不到定位器
  • 查看回复this question的三个提供的解决方案(@AmitJain 在此处建议的解决方案之一)
  • @BillHileman 感谢您分享此信息。但我仍然遇到同样的问题。在我的应用程序中首先弹出打开,所以我无法获取页面的坐标。首先我需要单击允许弹出然后我可以使用应用程序。我也用过。 driver.runAppInBackground(Duration.ofSeconds(3));但仍然存在同样的问题。你能建议任何其他方式吗

标签: java selenium-webdriver appium appium-android java-client


【解决方案1】:

appium 有一个open issue:解除警报后,appium 不再检测任何字段。

解决方法:

您可以将应用程序置于后台并再次启动。 driver.runAppInBackground(5);

在打开对话框之前获取屏幕上任何元素的坐标(x,y)与对话框交互(例如选择元素,关闭等)在关闭对话框后通过坐标(x,y)点击:new TouchAction(驱动程序).tap( x, y).perform();

【讨论】:

  • 我已经检查了 driver.runAppInBackground(Duration.ofSeconds(3));并且仍然得到同样的错误。当我们启动应用程序时,首先会弹出显示,所以在弹出之前我无法获取坐标
  • 屏幕上有任何其他元素,或者您可以创建 XPath 并获取元素坐标。或首先单击权限弹出窗口,然后在后台运行该应用程序。当它出现在前台时它应该可以工作
  • 感谢 shiv 的回复,但这不起作用。
  • 是肯定的 public void allowAccessLocation() { if(permAlert.isDisplayed()) { permAlert.click(); Utils.PauseTestExecution(2); driver.runAppInBackground(Duration.ofSeconds(3)); Utils.getScreenSizeCordinateAndClickOnScreen(driver); } else { System.out.println("弹出窗口不可用"); Utils.getScreenSizeCordinateAndClickOnScreen(driver); } }
  • 如果我使用的是 driver.runAppInBackground(5),则错误消息显示“InteractsWithApps 类型中的方法 runAppInBackground(Duration) 不适用于参数 (int)。”我认为现在我们需要这样写 driver.runAppInBackground(Duration.ofSeconds(3));
猜你喜欢
  • 2021-03-22
  • 2021-01-22
  • 2017-10-30
  • 1970-01-01
  • 1970-01-01
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多