androidseleniumwebdriverbrowserstackremotewebdriver

Selenium Android web test 'Save Card?' pop-up blocking test clicks


Hey I am having an issue with Selenium web tests with the Chrome mobile browser running on an Android device through Browserstack.

When I enter card details, the'Save Card?' pop-up appears and prevents test clicks on web elements that it covers:

enter image description here

Ive have tried a few solutions such as passing chrome arguments through to Browserstack but they seem to do nothing to stop this pop-up.

I've also tried to use context switching:

driver.context("NATIVE_APP"); 
driver.findElement(AppiumBy.xpath(".//android.widget.Button[@text='SAVE']")).click();

However this only works when specifying an 'AndroidDriver' but I am using 'RemoteWebDriver'.

My WebDriver sample code:

protected WebDriver driver;

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", "Samsung Galaxy S21 - " + method.getName());
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Samsung Galaxy S21");
capabilities.setCapability("browser", "Chrome");
capabilities.setCapability("real_mobile", "true");
capabilities.setCapability("browserstack.appium_version", "1.22.0");
capabilities.setCapability("browserstack.local", "true");
capabilities.setCapability("browserstack.networkLogs", "true");
capabilities.setCapability("autoGrantPermissions", "true");
capabilities.setCapability("disable-popup-blocking", "true");
capabilities.setCapability("autoDismissAlerts", true);
capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);

driver = new RemoteWebDriver(new URL(Browserstack_URL), capabilities);

Is there any way for me to close this pop-up or stop it appearing altogether while using RemoteWebDriver?


Solution

  • Had to end up switching to using:

    driver = new AndroidDriver(...)
    

    Then switching context & clicking 'Save':

    driver.context("NATIVE_APP");
    driver.findElement(By.xpath(".//android.widget.Button[@text='Save']")).click();