简体   繁体   中英

Appium xpath attribute text

An Android 4.4.4 physical smart phone device is sitting on USB tether, ADB enabled. Attempts are being made to automate a hybrid android application on this device via Appium (Java).

We are experiencing trouble reconciling elemental discovery and access behavior.

For example:

List<WebElement> buttons = driver.findElements(By.xpath("//android.widget.Button[@text='Something']"));

System.out.println("Found " + buttons.size() + " buttons.");

for ( WebElement el : buttons ) {
         System.out.println(el.getAttribute("text"));
}

One (1) button is discovered. The button found clearly has a "text" attribute containing "Something". However, when trying to print the contents of the "text" attribute the result is empty; just a line return.

Additionally, when the .click(); method is invoked, the element "clicked" is NOT the element found. In fact, according to the UI xml of the app, the element clicked isn't even an android.widget.Button .

Any ideas regarding what could be causing this unexpected behavior?

Thanks in advance.

As you are saying that you are automating a hybrid application so you have to switch context before perform any action like sendkeys or click or tap. so refer to context switch tutorials and try. Basically you are on native context and for hybrid app context should be changed to webview .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM