I want to get document height for various url, basically it's suppose to be the jQuery equivalent of $(document).height()
for all pages. How should I go about this?
I am comfortable using Python and JavaScript.
If you want browser's window size then you can use.
get_window_size(windowHandle='current')
Gets the width and height of the current window.
Usage: driver.get_window_size()
But that is not same as $(document).height()
, which you have asked for, so the only way to do it is to trigger the same JavaScript command using execute_script
.
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("http://google.com")
driver.maximize_window()
height = driver.execute_script("return document.body.scrollHeight")
print height
Note: If you want to execute the jQuery command, then you'll have to do below.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://google.com")
driver.maximize_window()
with open('jquery-1.9.1.min.js', 'r') as jquery_js:
jquery = jquery_js.read() #read the jquery from a file
driver.execute_script(jquery) #active the jquery lib
height = driver.execute_script("return $(document).height()")
print height
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With