Created
October 31, 2018 04:47
-
-
Save super-fishz/49b3d1eafef200448a47fe2216e8fb93 to your computer and use it in GitHub Desktop.
xpath 스트링에서 리프 노드를 제외하고 탐색하면서, 찾으려는 문자열이 일정 회수 반복될때까지 탐색한다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xpath = "//android.widget.FrameLayout/android.widget.FrameLayout[@index=‘0’]/android.widget.FrameLayout[@index=‘0’ and @resource-id=‘android:id/content’]/android.view.ViewGroup[@index=‘0’]/android.widget.LinearLayout[@index=‘0’ and @resource-id=‘com.android.packageinstaller:id/dialog_container’]/android.widget.LinearLayout[@index=‘1’]/android.widget.LinearLayout[@index=‘0’ and @resource-id=‘com.android.packageinstaller:id/button_group’]/android.widget.Button[@index=‘1’ and @resource-id=‘com.android.packageinstaller:id/permission_allow_button’]" | |
function getParentNode(arr, key, count) { | |
let _count = 0; | |
let line = 0; | |
const _arr = arr.reverse(); | |
for (let chunk of _arr.slice(1, _arr.length - 1)) { | |
line++; | |
if (chunk.indexOf(key) > -1) | |
_count++; | |
if (_count == count) | |
break; | |
} | |
return _arr.slice(0, line + 1).reverse() | |
} | |
const _split_pattern = new RegExp("(?<!id)/"); | |
getParentNode( xpath.split(/(?<!id)\//).map(it => `/${it}`), '@resource-id', 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment