selenium-webdriverseleniumbase

can't understand Error encountered: Message: Element was not present


Sorry, I am still learning the Python language and I am trying to apply it to this site, but I cannot understand the problem. Can you help?

    from seleniumbase import SB
    
    # OPEN LOGIN PAGE
    with SB(uc=True) as sb:
    sb.driver.uc_open_with_reconnect(
        "https://visa.vfsglobal.com/egy/en/hrv/login",
        reconnect_time=12
    )
    print("Site: VFS Global OPEN LOGIN PAGE >>>>> Success")
    
    # Define functions
    def login():
        # Search For Cookies
        sb.click("#onetrust-reject-all-handler")
        sleep(3)
    
    while True:
    try:
        login()
    except Exception as e:
        print(f'Error encountered: {e}')
    finally:
        sleep(2)
        quit()  # Indentation adjustment needed here

# End of your script

Terminal

 Site: VFS Global OPEN LOGIN PAGE >>>>> Success Error encountered: Message:   
    Element {#onetrust-reject-all-handler} was not present after 7 seconds!

But when delete

def login():

everything work fine why this issue?


Solution

  • Ignore the cookie section at the bottom of the page. If you're just trying to click the Turnstile, this will do:

    from seleniumbase import SB
    
    with SB(uc=True) as sb:
        sb.driver.uc_open_with_reconnect(
            "https://visa.vfsglobal.com/egy/en/hrv/login",
            reconnect_time=8
        )
        sb.driver.uc_switch_to_frame("iframe")
        sb.driver.uc_click("span.mark")
        breakpoint()
    

    (If your internet connection is slow, raise the reconnect_time.)