palak bansal palak bansal - 5 months ago 52
Python Question

stop loading page selenium as soon as pyqt button is clicked

from selenium import webdriver
driver.get("")#page that take too much time to load

Since this page took too much time to load I want to stop loading that page as soon as I click a pyQt button and start filling form.I dont want to use browser.set_page_load_timeout as I dont know when to stop

def stop_page_load():
global driver
"""What should be the definition so that as soon as I
click btn4,browser should stop loading"""

###w is a QWidget
btn4=QtWidgets.QPushButton("stop page load",w)

Answer Source

You need to load firefox with pageLoadStrategy as none. Then you can stop the page loading, but the side effect of this is that you will need to wait for loading of page yourself at all places as selenium won't do that automatically for you. You can also use eager instead of none which would wait for readyState of page to be true, but still give you sometime for page to load

import time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver

cap = DesiredCapabilities.FIREFOX
cap["pageLoadStrategy"] = "none"
driver = webdriver.Firefox(capabilities=cap)

driver.get("")#page that take too much time to load

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download