- Chrome version: 105.0.5195.102
- Selenium == 4.4.3
- Python == 3.9.12
In a certain page, 'element.text' takes ~0.x seconds which is unbearable. I suppose 'element.text' should return literally just a text from a cached page so couldn't understand it takes so long time. How can I make it faster?
Here are similar QNAs but I need to solve the problem just with Selenium.
Another question: Why every 'element.text' takes different times?
For example,
import chromedriver_autoinstaller
import time
from selenium import webdriver
chromedriver_autoinstaller.install(cwd=True)
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--no-sandbox')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-dev-shm-usage')
options.add_experimental_option("excludeSwitches", ["enable-logging"])
wd = webdriver.Chrome(options=options)
wd.get("https://www.bbc.com/")
t0 = time.time()
e = wd.find_element(By.CSS_SELECTOR, "#page > section.module.module--header > h2")
print(time.time()-t0)
for i in range(10):
t0 = time.time()
txt = e.text
print(time.time()-t0)
# This prints different result for every loop.
wd.quit()