Reputation: 91
I am attempting an automated test using appium java, and trying to create a variable for an element, but the test always fail.
If i do the following:
System.out.println(driver.findElement(By.id("android:id/message")))
it will print the text from the box.
If i attempt the followings, a "NoSuchElement" error will be displayed:
WebElement element = driver.findElement(By.id("android:id/message"));
System.out.println(element.getText());
or
MobileElement element = (MobileElement) driver.findElement(By.id("android:id/message"));
System.out.println(element.getText());
How should i declare a variable in order to be used later on the test?
Upvotes: 1
Views: 1845
Reputation: 1370
Try this:
WebElement element = driver.findElement(By.id("android:id/message"));
String print = element.getText();
System.out.println("Print my text " + print);
Upvotes: 2