2016-09-18 81 views
1

後接受按鈕我已經使用如何點擊拍照硒

self.driver.keyevent(27) 

捕捉Python中的圖像與selenium。但是,我得到的屏幕如下所示。

基本上我需要單擊接受按鈕(帶紅色邊框),以便圖像捕捉完成。我知道,我可以在adb外殼中使用,

input tap 1000 1500 

而且它的效果很好。但是,如何使用Python腳本實現相同?

enter image description here

即使只是通過硒腳本來執行這種方式將是對我OK

input tap 1000 1500 

喜歡的東西self.driver.execute( 「亞行外殼輸入抽頭1000 1500」);

回答

1

在Python中,按座標點擊元素的情況並不常見,請嘗試查找此接受按鈕的Xpath或Css選擇器表達式?

對於Android的測試,您可以考慮使用this tool

下面是關於如何點擊一對座標,你可以看到,你需要使用一個元素作爲參考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() 

既然您需要定位一個元素作爲參考,爲什麼不直接點擊這個元素而不使用座標?

+1

謝謝。唯一的問題是,這是Android手機的相機應用程序現在打開,所以我們不再在Web上下文中。所以我已經成功地拍攝了一張照片。但我必須接受圖像才能返回到打開相機的應用程序。因此,我需要的代碼是用於單擊相機應用程序上的接受圖像按鈕。 – Telewa

0

所以我想通了。

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