appium 利用相對座標解鎖九宮格

2021-07-12 01:37:07 字數 3121 閱讀 7401

一、獲取座標位置

我用的是hm2a:手機設定--其他高階設定--開發者選項--開啟指標位置

二、程式設計實現

利用touchaction

final touchaction gesture = new touchaction(driver).press(172, 598).waitaction(1000)

.moveto(360, 598).moveto(360, 770).moveto(360, 942).moveto(548, 942).release();

gesture.perform();

final touchaction gesture = new touchaction(driver).press(172, 598).waitaction(1000)

.moveto(188, 0).moveto(0, 172).moveto(0, 172).moveto(188, 0).release();

gesture.perform();

終於大功告成,現在來看一下該手勢的實現過程

2,"y":598}]

info: [debug] [bootstrap] [debug] got data from client: }

info: [debug] [bootstrap] [debug] got command of type action

info: [debug] [bootstrap] [debug] got command action: touchdown

info: [debug] [bootstrap] [debug] display bounds: [0,0][720,1280]

info: [debug] [bootstrap] [debug] performing touchdown using element? false x: 1

72, y: 598

info: [debug] [bootstrap] [debug] returning result:

0,"y":598}]

info: [debug] [bootstrap] [debug] got data from client: }

info: [debug] [bootstrap] [debug] got command of type action

info: [debug] [bootstrap] [debug] got command action: touchmove

info: [debug] [bootstrap] [debug] display bounds: [0,0][720,1280]

info: [debug] [bootstrap] [debug] performing touchmove using element? false x: 3

60, y: 598

info: [debug] [bootstrap] [debug] returning result:

0,"y":770}]

info: [debug] [bootstrap] [debug] got data from client: }

info: [debug] [bootstrap] [debug] got command of type action

info: [debug] [bootstrap] [debug] got command action: touchmove

info: [debug] [bootstrap] [debug] display bounds: [0,0][720,1280]

info: [debug] [bootstrap] [debug] performing touchmove using element? false x: 3

60, y: 770

info: [debug] [bootstrap] [debug] returning result:

0,"y":942}]

info: [debug] [bootstrap] [debug] got data from client: }

info: [debug] [bootstrap] [debug] got command of type action

info: [debug] [bootstrap] [debug] got command action: touchmove

info: [debug] [bootstrap] [debug] display bounds: [0,0][720,1280]

info: [debug] [bootstrap] [debug] performing touchmove using element? false x: 3

60, y: 942

info: [debug] [bootstrap] [debug] returning result:

8,"y":942}]

info: [debug] [bootstrap] [debug] got data from client: }

info: [debug] [bootstrap] [debug] got command of type action

info: [debug] [bootstrap] [debug] got command action: touchmove

info: [debug] [bootstrap] [debug] display bounds: [0,0][720,1280]

info: [debug] [bootstrap] [debug] performing touchmove using element? false x: 5

48, y: 942

info: [debug] [bootstrap] [debug] returning result:

三、後記

九宮格座標解鎖核心是利用座標的偏移量,但是不同手機的螢幕解析度不一樣,所以此方法不是很可取;如果可以定位空格的元素,推薦用文章剛開始的那個鏈結的方法,有興趣的可以自己實踐一下~~

Appium Python九宮格密碼解鎖

整體思路 獲取整個九宮格的view,然後計算出view的寬度和高度,從而計算出九宮格中每個點的座標位置,再通過touchaction driver press x,y move to x,y release perform 這個方法來繪製自己需要繪製的手勢密碼 實現如下 需要匯入的 def getu...

iOS 九宮格解鎖原始碼

專案原始碼 布局 北京是乙個imageview 中間是乙個view 連線自定義lockview 實現思路 1 新增9個button 2 監聽觸控事件 如果觸控點在button上則設定button的selected yes 3 把觸控過程中的button新增到集合 4 繪製線條 此view未做成功處理...

Java實現九宮格滑動解鎖

實現思路 為了適應不同螢幕的滑動解鎖,實現思路 1.獲取九宮格patterview的起始座標x y 2.獲取九宮格patterview的寬度 width 高度 height 3.九宮格的九個格仔大約平均把patterview的長 寬平均分成了4個等分,寬度間隔為width 4 高度間隔為height...