This article brings you an introduction to the methods of obtaining element status in Appium and Java. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. We often use the attributes of the
element. After locating an element, we sometimes need to use the text value, className, resource-id, checked, etc. of this element.
Generally standard attributes can be obtained through get_attribute("attribute name"). Let's take a look at how to obtain the elements in the screenshot below. Viewed from top to bottom.
Let’s start with text. We first locate this element through 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();//下一步 }
The methods to obtain the element status in sequence are:
element.getAttribute("checked")element.getAttribute("text") element.getAttribute("resource-id") element.getAttribute("name") name是获取content-desc的值 element.size() element.location()
And so on...
Special note: as long as the attribute value in the element is Boolean, that is, false or true. They can all be obtained through this method, so I won’t list them one by one. The second method here is often used, so focus on mastering it! !
The above is the entire content of this article. For more exciting information about Java, you can pay attention to the Java Video Tutorial and Java Development Tutorial columns on the PHP Chinese website! ! !
The above is the detailed content of Introduction to methods of obtaining element status in Appium and Java. For more information, please follow other related articles on the PHP Chinese website!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!