Answer the question
In order to leave comments, you need to log in
Why does it take so long for the click() function to be processed when measuring time in Selenium?
Good afternoon!
I began to write a test through a bunch of selenium + python + IE
But a rather strange picture happened - you need to measure the time from the moment you click on the link - until the page is loaded using the link
:
#
self.elem = self.driver.find_element_by_link_text("Ссылка")
self.test01 = time.time() #первый вариант
self.elem.click()
self.test02 = time.time() # второй вариант
assert "Страница по ссылке" in self.driver.page_source
self.test = time.time()
print(self.test-self.test01) #примерно 4 секунды
print(self.test-self.test02) #примерно 0.2 секунды
Answer the question
In order to leave comments, you need to log in
What are you measuring? Why do you need time between pressing and immediately after? Measure at the anchor after pressing.
upd:
By anchor, I meant that it is necessary to stop measuring when you see the element you need on the page.
In this example, the input field for the Question Detail
For example:
from selenium import webdriver
import time
from datetime import datetime
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver.get('https://www.toster.ru')
time.sleep(3)
driver.find_element_by_xpath('//a[@class="btn btn_green btn_add-question"]').click()
time1 = datetime.now()
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//textarea[@class='field__input textarea']"))
)
finally:
time2 = datetime.now()
delta = time2 - time1
print(delta)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question