I have created a facebook bot that logs in after a time but in case of slow internet i want bot to stop and close driver but i can't perform this operation until the page is loaded.
CodePudding user response:
I think you have to use a timeout to load the page wrapped in try-catch mechanism. If the page does not load within the given time, then the driver should close. Now, I am a python guy and so I cannot write code in JS and show you, but you may transform this to your language as required.
driver.get('x.com')
try:
# wait until an element in the page loads (typically one of the last elements that loads) within the given time (here it is 10 seconds timeout)
webdriverwait.until(EC.visibility_of_element_located(By.XPATH, "locator"),10)
except:
driver.close()
OR
You may try IMPLICIT_WAIT with a timeout. Eg:
driver.implicitly_wait(10)