Home > Enterprise >  What does the driver.execute_script("window.stop();") do in python selenium?
What does the driver.execute_script("window.stop();") do in python selenium?

Time:10-03

def scrape_scholar(keyword) :
    try :
        url = 'https://scholar.google.com/scholar?hl=en&as_sdt=0,5&as_ylo=2017&q=&btnG='
        option = webdriver.ChromeOptions()
        driver = webdriver.Chrome("./UI/chromedriver", options=option)
        wait = WebDriverWait(driver, 2000)
        driver.get(url)
        wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="gs_hdr_frm"]/div[1]/input')))
        driver.execute_script("window.stop();")

I don't know the role of the last instruction in python scraping.

CodePudding user response:

I have checked your code. And javascript command window.stop() stops a page load. This command basically is used when page is loading for a long time, because it has many elements or huge ajax communications.

Anyways, you can use this command when stop a page loading before a certain time, in python.

Hope to be helpful for you. Thanks.

CodePudding user response:

window.stop();

is basically to stop a page loading.

Also that's a JS command, so for that you have used execute_script.

In Python-Selenium, execute_script is a way to execute Javascript commands.

It basically depends on your use case, whether to use driver.execute_script("window.stop();") or other commands.

  • Related