Appium xpath attribute text
Android 4.4.4 physical smartphone devices are on a USB tether with ADB
enabled.
An attempt is being made to automate a hybrid android application on this device via Appium
(Java).
We had trouble coordinating element 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 found.
The found button obviously has a “text” property that contains “Something”.
However, when you try to print the contents of the Text property, the result is empty; Just one line back.
Also, when .click();
When the method is called, the “clicked” element is not the found element. In fact, according to the app’s UI xml, the element clicked isn’t even android.widget.Button.
Any ideas on what might be causing this unexpected behavior?
Thanks in advance.
Solution
As you said, you’re automating hybrid applications, so you have to switch contexts before doing anything like sendkeys
or clicking or tapping.
So reference the context switch tutorial and try. Basically you’re in the native context, and for hybrid applications, the context
should change to webview
.