最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
[content-description]find_element_by_accessibility_id在android中的詳解

出處:http://testerhome.com/topics/1034

創(chuàng)新互聯(lián)建站服務(wù)項(xiàng)目包括冷水江網(wǎng)站建設(shè)、冷水江網(wǎng)站制作、冷水江網(wǎng)頁制作以及冷水江網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,冷水江網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到冷水江省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

最近 Appium 引入了一個新的 find element 方法:python client 為例

def find_element_by_accessibility_id(self, id):         """Finds an element by accessibility id.          :Args:          - id - a string corresponding to a recursive element search using the          Id/Name that the native Accessibility options utilize          :Usage:             driver.find_element_by_accessibility_id()         """         return self.find_element(by=By.ACCESSIBILITY_ID, value=id) 

文檔里是這樣說的:

Allows for elements to be found using the "Accessibility ID". The methods take a
string representing the accessibility id or label attached to a given element, e.g., for iOS the accessibility identifier and for Android the content-description. Adds the methods
driver.find_element_by_accessibility_id and find_elements_by_accessibility_id.

意思就是可以使用 "Accessibility ID" 來定位元素。對于 iOS 而言就是 accessibility identifier。
對于 Android 就是 content-description。

那什么是 content-description 呢?

官方是這樣說的:

http://developer.android.com/training/accessibility/accessible-app.html
Android has several accessibility-focused features baked into the platform, which make it easy to optimize your application for those with visual or physical disabilities. However, it's not always obvious what the correct optimizations are, or the easiest way to leverage the framework toward this purpose. This lesson shows you how to implement the strategies and platform features that make for a great accessibility-enabled Android application.

這個屬性,主要是為了一些有殘障的人士準(zhǔn)備的,方便他們使用程序,所以這個警告前面會有一個[Accessbility]。

舉個例子,比如你有個 ImageView 放一張圖片,這個圖片可能包含很多物體和顏色,一些色弱或者色盲的人,他們可能會分不清這個圖到底畫的什么東西,所以這個時候 contentDescription 就會起作用。比如可能 Android 的一些程序可以用聲音告訴使用者這個圖片畫的是什么,他們讀的就是你 contentDescription 的內(nèi)容。

這其實(shí)和 iOS 的 accessibility identifier 是一樣的。

給一些需要加 contentDescription 的控件加 contentDescription 是一個良好的編程習(xí)慣,事實(shí)上 , ADT 的 Lint 檢測也會提示你:

[Accessibility] Missing contentDescription attribute on image 

所以給你的控件加上 android:contentDescription="@string/desc, 這樣也可以讓 Appium 來定位。

如何判斷是否加了 android:contentDescription?
  • 第一種方法,看控件的 xml 是否加了 android:contentDescription 屬性。
  • 第二種,看代碼,myView.setContentDescription(desc);
  • 第三種,使用 Hierarchy Viewer

[content-description] find_element_by_accessibility_id 在 android 中的詳解

appium sample-code 里面的 android_complex.py 實(shí)際上得用 https://github.com/appium/android-apidemos 這個project 來導(dǎo)出 apk 來測試。

    def test_find_elements(self):         # pause a moment, so xml generation can occur         sleep(2)          els = self.driver.find_elements_by_xpath('//android.widget.TextView')         self.assertEqual('API Demos', els[0].text)          el = self.driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "Animat")]')         self.assertEqual('Animation', el.text)          el = self.driver.find_element_by_accessibility_id("App")         el.click()          els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')         # there are more, but at least 10 visible         self.assertLess(10, len(els))         # the list includes 2 before the main visible elements         self.assertEqual('Action Bar', els[2].text)          els = self.driver.find_elements_by_xpath('//android.widget.TextView')         self.assertLess(10, len(els))         self.assertEqual('Action Bar', els[1].text) 
其他

試用了下 genymotion, 非常好用,用來做 Appium 實(shí)驗(yàn)很棒。

使用模擬器的時候遇到了個問題:

java.lang.IllegalArgumentException: eglChooseConfig failed EGL_NOT_INITIALIZED  03-29 13:21:34.556: E/AndroidRuntime(4458): FATAL EXCEPTION: main 03-29 13:21:34.556: E/AndroidRuntime(4458): Process: com.example.news, PID: 4458 03-29 13:21:34.556: E/AndroidRuntime(4458): java.lang.IllegalArgumentException: eglChooseConfig failed EGL_NOT_INITIALIZED 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.chooseEglConfig(HardwareRenderer.java:1173) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.loadEglConfig(HardwareRenderer.java:1135) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.initializeEgl(HardwareRenderer.java:1117) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:1057) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1550) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer.doFrame(Choreographer.java:544) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.os.Handler.handleCallback(Handler.java:733) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.os.Handler.dispatchMessage(Handler.java:95) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.os.Looper.loop(Looper.java:136) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.app.ActivityThread.main(ActivityThread.java:5017) 03-29 13:21:34.556: E/AndroidRuntime(4458): at java.lang.reflect.Method.invokeNative(Native Method) 03-29 13:21:34.556: E/AndroidRuntime(4458): at java.lang.reflect.Method.invoke(Method.java:515) 03-29 13:21:34.556: E/AndroidRuntime(4458): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 03-29 13:21:34.556: E/AndroidRuntime(4458): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 03-29 13:21:34.556: E/AndroidRuntime(4458): at dalvik.system.NativeStart.main(Native Method) 

Google了一下,關(guān)聯(lián)到了opengl es,這個了解過,初步懷疑不是我應(yīng)用的問題,最后查得居然是模擬器的問題,重啟后解決問題。


分享文章:[content-description]find_element_by_accessibility_id在android中的詳解
本文鏈接:http://fisionsoft.com.cn/article/psheop.html