Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在selenium中拍照后如何单击“接受”按钮_Android_Python_Selenium_Adb - Fatal编程技术网

Android 在selenium中拍照后如何单击“接受”按钮

Android 在selenium中拍照后如何单击“接受”按钮,android,python,selenium,adb,Android,Python,Selenium,Adb,我用过 self.driver.keyevent(27) 使用selenium在Python中捕获图像。然而,我得到的屏幕如下所示 基本上我需要点击accept按钮(带有红色边框),这样图像捕获就完成了。我知道,我可以在adb shell中使用 input tap 1000 1500 而且效果很好。但是如何使用Python脚本实现同样的效果呢 即使只是一种通过selenium脚本执行此操作的方法,对我来说也是可以的 input tap 1000 1500 类似于self.driver.e

我用过

self.driver.keyevent(27)
使用
selenium
在Python中捕获图像。然而,我得到的屏幕如下所示

基本上我需要点击accept按钮(带有红色边框),这样图像捕获就完成了。我知道,我可以在adb shell中使用

input tap 1000 1500
而且效果很好。但是如何使用Python脚本实现同样的效果呢

即使只是一种通过selenium脚本执行此操作的方法,对我来说也是可以的

input tap 1000 1500

类似于self.driver.execute(“adb外壳输入tap 1000 1500”)

在Python中,按元素的坐标单击元素是不常见的,请尝试查找此accept buttons的Xpath或Css选择器表达式好吗

对于Android测试,可以考虑使用

下面是一个Python代码片段,介绍了如何单击一对坐标,正如您所看到的,您需要使用一个元素作为引用

from selenium import webdriver
driver = webdriver.Firefox() //Or whichever browser you prefer
driver.get("your url")
reference=driver.find_elements_by_xpath("Your xpath here")

action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(reference, X, Y)
action.click()
action.perform()
既然你需要定位一个元素作为参考,为什么不直接点击这个元素而不用坐标呢?

所以我想出来了

import subprocess
subprocess.call(["adb", "shell", "input keyevent 27"]) # capture
subprocess.call(["adb", "shell", "input tap 1000 1500"]) # accept the captured image

谢谢唯一的问题是,android手机的一个摄像头应用程序目前已经打开,因此我们不再处于网络环境中。所以我已经拍到了一张照片。但我必须接受图像,才能将图像返回到打开相机的应用程序。因此,我需要的代码是用于单击相机应用程序上的“接受图像”按钮。