python测试selenium等待时间,并输出log,设置log级别

复制代码
__author__ = 'Jeff.xie'

import logging

from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep

# selenium 等待的3种方式

# timd.sleep(固定等待)
# implicitly_wait(隐式等待)
# WebDriverWait(显示等待)

# level=logging.INFO LEVEL 设置为DEBUG,所有详细的log都会输出,建议设置成INFO,第三方包的log不会输出
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

# 记录不同级别的日志
logging.debug('这是一个debug消息')
logging.info('这是一个info消息')
logging.warning('这是一个warning消息')
logging.error('这是一个error消息')
logging.critical('这是一个critical消息')

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")

driver.implicitly_wait(10)
logging.info('debug start')
driver.find_element(By.ID,"kw").send_keys("Java")
WebDriverWait(driver,15,1).until(EC.presence_of_element_located((By.ID,"su"))).click()

sleep(0.1)

logging.info('debug finish')
driver.close()
相关推荐
Scott9999HH7 小时前
【IIoT流量实战】蒸汽管道阀门全关却仍有流量?用 Python 实现涡街信号 FFT 频谱分析与温压全补偿积算网关,深度拆解靠谱的涡街流量计厂家硬核技术标准
开发语言·python
码智社8 小时前
AES加密原理详解及Java实现加解密实战
java·开发语言
AI云海8 小时前
python 列表、元组、集合和字典
开发语言·python
二十雨辰8 小时前
[爬虫]-Urllib
爬虫·python
萧瑟余晖9 小时前
JDK 26 新特性详解
java·开发语言
马优晨9 小时前
Freemarker 完整讲解(后端 Java 模板引擎)
java·开发语言·freemarker·freemarker 完整讲解·freemarker模板引擎
玉鸯10 小时前
Agent Hook:在概率推理之上,为 Agent 叠加确定性控制
python·langchain·agent
weixin_4462608511 小时前
HACO:面向动态部署环境的对冲式智能计算可靠多智能体调度框架
后端·python·flask
我的xiaodoujiao11 小时前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest