Reusable pageSource


#1

Hi,
when doing any requests with driver.findElement() or element.getText(), etc. I suppose new getPageSource() is being called. Is that correct?

What I want to ask is, is there any way to use the same pageSource for next calls? In case when I have a static content, doing nothing but to read element’s labels - I want to save time not calling pageSource all over again, but use the same one (because i know, nothing on the screen changed).

Would be great to have a feature, e.g.:

 driver.freezePageSource(true);
 //Do the reading
 driver.freezePageSource(false);
 //Do some other actions that will actually change structure of the pageSource

I don’t know, this might not be possible. Enlighten me, please :bulb:

Any thoughts about that?


#2

You should create String variable and then set value of String variable as getPageSource(). If you want to find element in page source without any request, you can parse into the String variable’s value.


#3

Ohh ok… I know what you mean. That’s one way to create a custom parser and parse it out myself. :+1:
Same thing could be implemented for general use in Appium/Selenium.


#4

The page source only needs to be (re)built when xpath location is used or pageSource itself is called. Otherwise this is not necessary