You can download this code by clicking the button below.
This code is now available for download.
This function uses Selenium WebDriver with WebDriverWait to wait until an element on the page is found by its ID and returns the element.
Technology Stack : Selenium, WebDriver, WebDriverWait, EC (Expected Conditions)
Code Type : The type of code
Code Difficulty : Intermediate
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def find_element_by_id(driver, element_id):
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, element_id))
)
return element