AppiumDriver的各種findElement方法的嘗試,嘗試的目標應用是SDK自帶的Notepad應用。
el = driver.findElementByName("Add note"); assertThat(el.getText(),equalTo("Add note"));
安卓設備沒有找到適合的方法,嘗試用Appium Inspector,但是使用了當前最新的“AppiumForWindows-1.2.3.1”沒有看到這個屬性,且Inspector在Windows下面非常的不穩定,很容易crash。真心期望Appium團隊盡快解決這個問題
iOS設備倒可以用Appium Inspector獲得(以下圖片來自網上)
個人建議可以嘗試先用view顯示的文本作為name看是否能拿到該控件,按照我個人的經驗一般都是會成功的,所以我很懷疑安卓上面控件的name是否就等于text。如果確實還是不行的話就只好放棄用name了?;蛘叩却鼳ppium后來的穩定的inspector發布后看是否可以獲得控件的name。
這個方法在Appium1.0之后其實已經過時而要被findElementByAccessibilityId取代得了,不知道為什么還能調用,猜想是Appium團隊想保留一定的兼容性以平滑過度吧。請查看:https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/migrating-to-1-0.md
el = driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Add note\")"); assertThat(el.getText(),equalTo("Add note"));
UIAutomator獲取控件的方式多種多樣,都是通過UiSelector對象來去查找,比如使用view的text文本去當前窗口查找控件,這里不做累述,往后會另起一篇文章來描述UIAUtomator獲取控件的方式,到時直接套用進來就可以了。
el = driver.findElementByClassName("android.widget.TextView"); assertThat(el.getText(),equalTo("Add note"));
可以使用UIAutomatorViewer工具直接查看
使用ClassName一般獲得的view都不止一個,所以應該需要遍歷一遍得到的views,然后縮寫搜索條件來獲得目標控件。示例中因為只有一個textview控件在窗口上面,所以不需要遍歷。
el = driver.findElementById("android:id/title"); assertThat(el.getText(),equalTo("Add note"));
可以通過UIAutomatorViewer獲得
el = driver.findElementByAccessibilityId("menu_add_note_description"); assertThat(el.getText(),equalTo("node"));
el = driver.findElementByXPath("//android.widget.TextView[contains(@text,'Add note')]"); //el = driver.findElement(By.xpath("//android.widget.TextView")); assertThat(el.getText(),equalTo("Add note"));
從老版本的Appium0.18.x升級到現在的Appium1.x后,注意class name和xpath策略的變化:你現在需要使用FQCN來描述你的控件。也就是說原來的:
findElementByXpath(""//TextView[contains(@text,'Add note')]"")
需要改成
findElementByXpath("//android.widget.TextView[contains(@text,'Add note')]")
詳細變動請查看《Appium0.18.x遷移到Appium1.x須知事項》
作者 | 自主博客 | 微信 | CSDN |
天地會珠海分舵 | http://techgogogo.com | 服務號:TechGoGoGo 掃描碼: | 向AI問一下細節 免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。 猜你喜歡最新資訊相關推薦相關標簽AI
助 手
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女
|
sometimes uiautomator fails to create the dump.xml. A client side retry may help. I don't think there's much we can do about the problem until Google fixes uiautomator.