請服用 WebDriverWait
def _get_elm_id(self, strID):
# https://selenium-python.readthedocs.io/waits.html
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.ID, strID)) and
EC.element_to_be_clickable((By.ID, strID))
)
return element
Reference
Further Reading
- Python Main Page - Web Automation 章節 (view)