I was watching YouTube video where I'd noticed that the following code:
import time
from selenium import webdriver
driver = webdriver.Chrome(executable_path="...") # here just creates new Chrome driver
try:
driver.get(URI)
time.sleep(3)
respond = driver.page_source
print(respond)
except Exception as _ex:
print(_ex)
finally:
driver.close()
driver.quit()
But at the same time it says that you don't have to use time.sleep
statement. Instead you can use WebDriverWait.
So my question is how could we refactor this code using WebDriverWait and why do we need to use wait here in general?