To make some measurements I have used the following simple Selenium code:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)
url = "https://www.bbc.com/"
driver.get(url)
wait = WebDriverWait(driver, 10)
# used this line to start the following measurements when the page is loaded
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".media.media--overlay.block-link")))
t0 = time.time()
e = driver.find_element(By.CSS_SELECTOR, "a#homepage-link")
print("By.CSS_SELECTOR " + str(time.time()-t0))
t0 = time.time()
e = driver.find_element(By.ID, "page")
print("By.ID " + str(time.time()-t0))
t0 = time.time()
e = driver.find_element(By.XPATH, "//a[@id='homepage-link']")
print("By.XPATH " + str(time.time()-t0))
t0 = time.time()
e = driver.find_element(By.PARTIAL_LINK_TEXT, "coffin travelling from Balmoral")
print("By.PARTIAL_LINK_TEXT " + str(time.time()-t0))
I have run it several times, the results are varying from run to run, but the typical output is as following:
By.CSS_SELECTOR 0.021941661834716797
By.ID 0.018949031829833984
By.XPATH 0.028922557830810547
By.PARTIAL_LINK_TEXT 0.6597516536712646
I.e. By.CSS_SELECTOR
, By.ID
and By.XPATH
are taking relatively similar access time while By.PARTIAL_LINK_TEXT
is mostly takes much more time.
Tested on Version 105.0.5195.102 (Official Build) (64-bit)
Google Chrome with latest Selenium 4 version on Windows 10 PC with 16 GB RAM
When tested with FireFox
the latest version I saw the similar values.
And again, each measurement is giving different values for each run, but mostly this is the picture, as above.