[英]Load Firefox with python selenium script, but it will open the skype support page
[英]Selenium Python Load Page and Script (Firefox and IE)
我对此并不了解,所以希望您能给我一些建议。
通常,当我使用Selenium时,我会尝试搜索我感兴趣的元素,但是现在我正在考虑进行某种性能测试,因此请检查将特定网页(html,脚本等)花费了多少时间。加载。
您是否知道如何在不搜索页面特定元素的情况下知道html,脚本等的加载时间?
PS我使用IE或Firefox
您可以检查基础javascript框架中的活动连接。 如果没有活动的连接,则可以假定页面已完成加载。
但是,这要求您要么知道页面使用的框架,要么必须系统地检查不同的框架,然后检查连接。
def get_js_framework(driver):
frameworks = [
'return jQuery.active',
'return Ajax.activeRequestCount',
'return dojo.io.XMLHTTPTransport.inFlight.length'
]
for f in frameworks:
try:
driver.execute_script(f)
except Exception:
logging.debug("{0} didn't work, trying next js framework".format(f))
continue
else:
return f
else:
return None
def load_page(driver, link):
timeout = 5
begin = time.time()
driver.get(link)
js = _get_js_framework(driver)
if js:
while driver.execute_script(js) and time.time() < begin + timeout:
time.sleep(0.25)
else:
time.sleep(timeout)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.