前言
一直想学习自动化测试,但是都没行动,业余时间学习零零碎碎并记录20210409
【Selenium核心技术篇】包含以下内容:
- Selenium实现元素定位(8种)
- Selenium WebDriver
- Selenium WebElement
- Selenium操作from表单
- Selenium操作checkbox和radiobutton
- Selenium操作下拉列表
- Selenium处理弹框
- Selenium三种等待方式
- Selenium等待条件
- Selenium鼠标和键盘事件
- Selenium执行JavaScript脚本
- Selenium屏幕截图
- Selenium之frame的切入和切出
selenium元素定位公用方法
from selenium.webdriver.common.by import By
"""
The By implementation.
"""
class By(object):
"""
Set of supported locator strategies.
"""
ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
实操
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
def get_element(driver,*loc):
e = driver.find_element(*loc)
return e
if __name__ == '__main__':
driver = webdriver.Chrome()
driver.get('http://wwww.baidu.com')
sleep(1)
# get_element(driver,By.ID,'kw').send_keys('留白')
# get_element(driver,By.ID,'su').click()
# driver.quit()
#优化上面3行
loc = (By.ID,'kw')
loc2 = (By.ID,'su')
#加*代表我们这个参数要解包
get_element(driver,*loc).send_keys('留白')
get_element(driver,*loc2).click()
sleep(3)
driver.quit()