Hello,
I am having a hard time getting the Android driver to accept Android alerts. I am using Python.
Are their alternatives to the examples below to get the system/device level popups to be dismissed?
The following does nothing:
# Try to dismiss any Android account alerts.
try:
alertObj = driver.switch_to.alert
alertObj.accept()
alertObj.dismiss()
log("Alert Accepted #1")
except BaseException as e:
log("Exception! " + str(e))
# Try to dismiss any Android account alerts.
try:
driver.switch_to.alert.accept()
log("Alert Accepted #2")
except BaseException as e:
log("Exception! " + str(e))
# Try to dismiss any Android account alerts.
try:
driver.switch_to.alert.dismiss()
log("Alert Accepted #3")
except BaseException as e:
log("Exception! " + str(e))
This works for me.
What Appium Version are you using?
iosdriver.switchTo().alert().accept();
try {Thread.sleep(2000);}catch (Exception e) {}
iosdriver.switchTo().alert().accept();
try {Thread.sleep(2000);}catch (Exception e) {}
iosdriver.navigate().back();
Hi, I don’t know the Appium version, as I am using a cloud service.
However, from my bash script, here is the Appium Python Client version (0.23)
echo “Installing Appium Python Client 0.23”
tar -xvf Appium-Python-Client-0.23.tar.gz
cd Appium-Python-Client-0.23
python setup.py install --user
cd …
Here is the exception received trying to dismiss alerts
Message: Not yet implemented. Please help us: http://appium.io/get-involved.html
You should be able to click on it in NATIVE_APP context
Hi Hardik_d. Can you elaborate on this answer?
I’ve tried the following methods with no success:
self.driver.switch_to.alert.accept() # Also trying instantiating the alert first, and then calling alert.accept()
self.driver.find_element_by_android_uiautomator(‘new UiSelector().packageName(“com.android.systemui”)’).click()
self.driver.find_element_by_name(‘Allow’).click()
self.driver.find_element_by_id(‘android:id/button1’).click()
self.driver.find_element_by_class_name(‘android.widget.Button’).click()
i use appium 1.6.3 and ruby, here are couple examples:
wait(5){@driver.find_element(:xpath, “//*[@text=‘Cancel’]”).click}
wait(5) { @driver.find_element(:accessibility_id, “OK”).click }
After spending COUNTLESS hours trying to figure this out. I’ve finally got it!
acceptButton = self.driver.find_element_by_text("Allow")
action = TouchAction(self.driver)
action.tap(acceptButton).perform()
This was insanely hard to find. Documentation is not straightforward about how click does not work well on devices. But at least this fixed my issue!
To review:
- Switch to alert, then accepting alert, did not work
- Finding the element and then performing a click, did not work
3) Finding the element and then performing a tap, did work!
Hi,
Presently we don’t have any mechanism to identify the alert in the android.
we have to treat them as the normal elements.
I tried your way, but it doesnt work
How do you treat them as normal elements? I tried treating them as normal elements and appium wont detect?
found https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md that with appium 1.6.3 they have added capabilities.setCapability(“autoGrantPermissions”, “true”); this should solve the problem.