[Python] How to ensure the results-section got refreshed after a button click using python and...

Discussão em 'Python' iniciado por Stack, Junho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am doing web scraping using python selenium with the website

    I will be input a value to Search value textbox and click on the Search now Button. This is all happening inside a for loop.

    Sending value to textbox and button click everything is working fine. Since the search results are appearing on the same web page how do I ensure the results section got refreshed before I am reading the data to make sure I am not reading any stale data.


    I am doing this search based on Isin code by selecting it from LEI Data Field.
    ​

    def read(value):
    search_textbox = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH ,"//input[contains(@class,'input') and @type='text']")))
    search_textbox.click()
    time.sleep(1)
    search_textbox.clear()
    time.sleep(1)

    script = """
    var input = arguments[0];
    var value = arguments[1];
    input.value = value;
    var event = new Event('input', { bubbles: true });
    input.dispatchEvent(event);
    """
    driver.execute_script(script, search_textbox, value)
    time.sleep(1)

    #Button
    search_btn = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH,"//button[contains(@class,'search-btn') and normalize-space(text())='Search now']")))
    search_btn.click()
    time.sleep(2)

    WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.ID, 'results-section')))
    results_section = driver.find_element(By.ID, 'results-section')

    return results_section


    for value in values:
    data = read(value)
    bla bla bla.....



    To me WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.ID, 'results-section'))) this piece of code seems doesn't really help to identify whether the results-secion got refreshed after button clicking on search button.

    How I ensure/wait the results-section got refreshed after the search button click ?

    I Am quite new to selenium. Appreciate your help on this.


    Example values: US035240AQ30, KYG040111059 & INE437A01024 (some values doesn't have any matching output )
    ​

    Continue reading...

Compartilhe esta Página