2016-03-23 32 views
3

如何訪問以單擊TextView內的第二個鏈接?到目前爲止,我嘗試:單擊TextView類中的鏈接

AndroidElement d = (AndroidElement) driver.findElement(By.xpath("//android.widget.TextView[@text='Notice']")); 
    d.click(); 

而且使用:

driver.findElement(By.Id("com.optimum.rdvr.mobile:id/toc_text")); 

只是點擊鏈接一號。我需要獲得第二個鏈接。我想點擊「移動隱私通知」任何人都有建議?

enter image description here

+0

您選擇父元素,因此很難說。選擇鏈接元素本身。嘗試使用Appium檢查器。 –

回答

0

您可以使用Linkify

String termsOfUse = getResources().getString(R.string.terms_of_use); 
String privacyNotice = getResources().getString(R.string.privacy_notice); 

legalDescription.setText(
    String.format(
     getResources().getString(R.string.message), 
     termsOfUse, 
     privacyNotice) 
); 

//add the links 
Pattern privacyNoticeMatcher = Pattern.compile(privacyNotice); 
Linkify.addLinks(legalDescription, privacyNoticeMatcher , "privacy:"); 
Pattern termsOfUseMatcher = Pattern.compile(termsOfUse); 
Linkify.addLinks(legalDescription, termsOfUseMatcher , "termsOfUse:"); 

通過Multiple Clickable links in TextView on Android

+0

但我只能訪問UI。我實際上測試應用程序,而不是開發它。有什麼想法嗎? –