Problem with gettext()

Hello,
I have a problem with the methode .gettext(),
I tryed to get a value on an app, the value change every 0.5second, I tryed something like:
for(…)
int first_value = Integer.decode(driver.findElement(By.xpath("//*[@x=‘32’]")).getText());
System.out.println("First value: "+first_value);

but it returns always the same value (even if the value change on the app), someone had the same problem?

Hi,

The for loop runs irrespective of the time it takes the values to change. Let’s say the value changes 5 times and you want to capture all 5 instances. You run the for loop but it runs and finishes before the value changes, effectively capturing the same element and its value over and over again.

if you are certain that the values change in intervals of 0.5 seconds, try to introduce a Thread.sleep() in your for loop, or perhaps a driver wait.until.
http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

I tried this:
String test = driver.findElement(By.xpath("//[@y=‘150’]")).getText(); // first value : 150
System.out.println("value: “+test);
Thread.sleep(15000);
String test2 = driver.findElement(By.xpath(”//
[@y=‘150’]")).getText(); // second value : 200
System.out.println("value: "+test2);

and it returned on the console:
value: 150
value: 150

I dont understand why…

EDIT: if I disconnect and connect the Iphone between 2 getText, the value is good, but it is very slow…

Hi, thanks for reporting the issue, we were able to recreate the issue over here, and it has to do with our internal caching mechanism.

We are still considering options to resolve this issue - for the time being, I’ll suggest an implementation that will wipe the cache before you get the text

String test = driver.findElement(By.xpath("//*[@y='150']")).getText(); // first value : 150
System.out.println("value: "+test);
driver.tap(0,1,1,100); //tap on some random location with no clickable element
String test2 = driver.findElement(By.xpath("//*[@y='150']")).getText(); // second value : 200
System.out.println("value: "+test2);

I’ll update you as-soon as we have a permanent resolution for the issue

2 Likes

Hi, I know this is an old thread, but i am facing similar kind of issue myself. When the text is changed it doesn’t read by the program(shows the old value). I tried TouchAction(driver).press method too, but it doesn’t work. Any input would be helpful, thanks