I'm using Selenium in Python 3.6 and it works fine, but not always. I have this code:
try:
table = wait.until(
EC.presence_of_element_located((
By.XPATH,
"/html/body/div/div[2]/div[1]/table/tbody/"
"tr[2]/td/table/tbody/tr/td/div/table[2]"
))
)
except TimeoutException:
driver.quit()
return {
"statusCode": 500,
"body": json.dumps({"error": "WebPage dont load"}),
"headers": {
"Content-Type": "application/json"
}
}
And this works, but sometimes there is a timeout exception, and I need this working 100% of the time. I already tried using time.sleep(5)
, presence_of_all_elements_located
, visibility_of_element_located
, function to wait the webpage to load, but the problem is not fixed.
Also I have:
driver.implicitly_wait(20)
and
wait = WebDriverWait(driver, 30)
to make waits implicit and explicit.