例如点击某个网页,然后输入网址点击搜索,马上开始计时,页面打开后检索到某个元素后停止计时,脚本停止
这样做能实现么?
输出两个时间戳不行吗?这样应该会比实际慢一点点,但是应该是.2s 左右
import datetime t1 = datetime.datetime.now() driver.get('url') driver.implicitly_wait(10) driver.find_element_by_id('target') t2 = datetime.datetime.now() duration = t2 - t1 print duration
from selenium import webdriver from timeit import Timer def search_time(driver): search_btn = xxx #替换搜索button的xpath driver.find_element_by_xpath(search_btn).click() target_element = xxx #替换目标元素xpath driver.find_element_by_xpath(target_element) test = Timer('search_time(driver)','from selenium import webdriver; \ from __main__ import search_time;\ driver = webdriver.Firefox(); \ driver.implicitly_wait(30);\ driver.get(url)') #替换url值 print test.timeit(1) #运行一次的时间 print test.repeat(10,1)/10 #计算运行10次的平均时间
=。=楼主要测搜索速度吗,可以用 jmeter 呀 (/ω╲)