2015-01-04 73 views
0

我正在尋找一種方式在Selendroid中獲取在真實設備上運行的應用程序的當前視圖轉儲。現在我知道,你可以得到整個頁面源與isClickable與Selendroid

driver.getPageSource() 

這就是,我目前正在使用。此方法爲我提供了所有可見視圖元素的XML格式的層次結構,可以使用XPath進行分析。輸出看起來像這樣:

<?xml version="1.0" encoding="UTF-8"?> 
<views> 
    <DecorView name="" label="" value="" ref="97bc5edf-6001-0c8a-3550-92822dfe3d55" id="" shown="true"> 
    <rect x="0" y="0" height="1920" width="1080" /> 
    <LinearLayout name="" label="" value="" ref="da84259b-f404-d100-7eb6-ed006469d60e" id="" shown="true"> 
    <rect x="0" y="0" height="1920" width="1080" /> 
    <ViewStub name="" label="" value="" ref="beb2dd1c-4a0e-25ef-26ff-30fa1eb628d0" id="action_mode_bar_stub" shown="false"> 
     <rect x="0" y="0" height="0" width="0" /> 
    </ViewStub> 
    (...) 

不幸的是,我只需要單擊元素,它可以被點擊。在Android SDK中,可以使用View上的isClickable來檢查是否存在爲其註冊的點擊偵聽器。

是否有可能使用Selendroid獲取元素的isClickable屬性?替代方法是否有任何其他方式來獲取應用程序的當前視圖轉儲與Selendroid,它會給我的元素的isClickable屬性值?

最後一件事:我正在做的是對應用進行通用測試,其中我沒有源代碼。因此,我無法在運行時定義視圖元素。這必須動態發生。

回答

0

您應該使用像uiautomatorviewer [位於SDK工具文件夾]中的工具來手動檢查進程。 Selendroid不提供像「isClickable」功能,但你可以chceck「isEnabled」或只是:

WebElement element = driver.findElement(/* ... */); 
try{ 
element.click(); 
}catch(SelendroidException ex){ 
/* your listener for output */ 
} 

或!

element = WebDriverWait(driver, 10).until(
ExpectedConditions.elementToBeClickable(/* way to identity element */)); 

是的..它真的很難找到正確的方法來做到這一點。

相關問題