I am working on a selenium script to visit a list of websites that install service workers. What I want to do is, if selenium visits a website, it should wait for the service worker to be installed before moving on to the next website or quitting the selenium driver. Currently, my code looks like the following.
for url in tqdm(list_urls):
driver = get_driver() # gets driver from helper function.
print(f'Doing {url} {list_urls.index(url)+1}/{len(list_urls)}')
try:
driver.get(url)
sleep(10) # probably not the best way to do it.
except: # if there is a selenium timeout exception.
print(f'{url} did not work ... will try again.')
repeat_list.append(url)
driver.quit()
I have a sleep(10) which I do not think is the best way to do it. There is a possibility that the service worker is installed in 1 second (it sits idle for 9 seconds doing nothing) or the service worker was not installed in 10 seconds. I am going to do this for a list of websites at the scale of thousands. I understand there are implicit, explicit, and fluent wait statements in selenium but I have not found anything that is useful for me.