一直以为,pc 的 chrome 和 移动 的 chrome web 自动化是一样的。对,大部分情况还是一样的,但是还是有些不太一样的地方。比如说:


可以通过 driver.switch_to.context("NATIVE_APP") 定位到弹窗内容,但是没有办法点击到按钮。

原来,此问题是可以通过 uiautomator viewer 定位到。

driver.switch_to.context("NATIVE_APP")
driver.implicitly_wait(min_wait_second)
driver.find_element(By.ID,"positive_button").click()
 
def accept_permission(driver):
    try:
        if "NATIVE_APP" in driver.contexts:
            driver.switch_to.context("NATIVE_APP")
            driver.switch_to.alert.accept()
    except Exception as err:
        print(err)
    driver.switch_to.context("CHROMIUM")