這篇文章帶給大家的內容是關於Appium和java取得元素狀態的方法介紹,有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。
元素的屬性我們常常會用到,當定位到某個元素後,有時會需要用到這個元素的text值、className、resource-id、checked等。
一般標準的屬性我們都可以透過get_attribute(「屬性名稱」)來獲取,我們來看看下面截圖的元素都是怎麼取得的吧。從上到下來看。
我們從text開始講,我們先透過xpath方式定位到這個元素
public class UIdemoTest { private AndroidDriver driver; @Before public void setUp() throws Exception { //设置并启动“app” File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "apps"); File app = new File(appDir, "com.sdu.doo.gsui.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("noReset", true);//不需要每次安装app capabilities.setCapability("deviceName", "85GBBMD22AJY"); capabilities.setCapability("automationName", "Appium"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("platformVersion", "5.1"); capabilities.setCapability("autoGrantPermissions","ture");//允许在手机上安装该app capabilities.setCapability("appPackage", "com.sdu.doo.gsui"); capabilities.setCapability("appActivity", "com.doo.driver.sdk.LauncherActivity"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), (Capabilities) capabilities); } @After public void tearDown() throws Exception { } @Test public void login () throws InterruptedException { // clearText(By.xpath()); driver.findElement(By.xpath("//android.widget.EditText[@resource-id='com.sdu.didi.gsui:id/et_phone' and @text = '请输入手机号码']")).click(); driver.pressKeyCode(8);driver.pressKeyCode(8);driver.pressKeyCode(7);driver.pressKeyCode(7);driver.pressKeyCode(7); driver.pressKeyCode(7);driver.pressKeyCode(7);driver.pressKeyCode(7);driver.pressKeyCode(13);driver.pressKeyCode(15); driver.pressKeyCode(8); Thread.sleep(1000); // WebElement element = (WebElement) By.xpath("//android.widget.CheckBox[@resource-id='com.sdu.didi.gsui:id/cb_law' and @checked = 'false']"); // WebElement element1 = (WebElement) By.id("com.sdu.didi.gsui:id/cb_law"); WebElement element = driver.findElement(By.xpath("//android.widget.CheckBox[@text = '同意']")); System.out.println(element.getAttribute("checked")); if (element.getAttribute("checked") == "false"){ driver.findElement(By.id("com.sdu.didi.gsui:id/cb_law") ).click();//同意 } driver.findElement(By.id("com.sdu.didi.gsui:id/btn_next")).click();//下一步 }
依序取得元素狀態的方法有:
element.getAttribute("checked")element.getAttribute("text") element.getAttribute("resource-id") element.getAttribute("name") name是获取content-desc的值 element.size() element.location()
以此類推...
特注意一點:元素裡只要屬性值是布林型的,即false or true。都可以透過這個方法來獲取,就不一一列出了。這裡的第二種方法常用到,重點掌握! !
以上就是這篇文章的全部內容了,關於Java的更多精彩可以關注PHP中文網的Java視頻教程和Java開發教程欄目! ! !
以上是Appium和java取得元素狀態的方法介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Java在不同操作系統上的表現存在細微差異。 1)JVM實現不同,如HotSpot、OpenJDK,影響性能和垃圾回收。 2)文件系統結構和路徑分隔符不同,需使用Java標準庫處理。 3)網絡協議實現差異影響網絡性能。 4)GUI組件外觀和行為在不同系統上有別。通過使用標準庫和虛擬機測試,可減少這些差異的影響,確保Java程序穩定運行。

javaoffersrobustobject-IentiendedProgrammming(OOP)和Top-Notchsecurityfeatures.1)OopinjavainCludesClasses,對象,繼承,多態性,和列出,andeclingfleximaintainablesys.ss.2)SecurityFeateTuersLudEtersludEterMachine(

JavaScriptandJavahavedistinctstrengths:JavaScriptexcelsindynamictypingandasynchronousprogramming,whileJavaisrobustwithstrongOOPandtyping.1)JavaScript'sdynamicnatureallowsforrapiddevelopmentandprototyping,withasync/awaitfornon-blockingI/O.2)Java'sOOPf

JAVAACHIEVESPLATFORMINDEPENTENCETHROUGHJAVAVIRTAILMACHINE(JVM)和BYTECODE.1)THEJVMINTERPRETSBBYTECODE,允許theingthesmecodetorunonanyanyanyanyplatformwithajvm.2)

java'splatformendependecemeansapplicationscanrunonanyplatformwithajvm,使“ Writeonce,runanywhere”。

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生產性。 1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允許CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。