一、如何定位标签:
html->body->div->input
<html>
<head>
<title>课堂</titile>
</head>
<body>
<div class='login'>
<input id="id_username">
</div>
</body>
</html>
(1)class定位
(2)id定位:
driver.find_element_by_id('id_username').send_keys("lulu")
#r如果是要上传文件,其实是send_leys()中发送文件所在的绝对路径
#下面介绍如何获取绝对路径i
import os
abs_path=os.getcwd()+'/'
driver.find_element_by_id('id_Pic_1').send_keys(abs_path+'123.png')
(3)xpath定位:点击网页->检查->查找元素->右键copy->copy Xpath
示例图片
driver.find_element_by_xpath('//*[@id=''login-form"]/div[3]/input').click()
(4)CSS定位(元素定位)
id在前端用#开始,class用.开始
id下面的标签用>表示,如果是一个标签直接>标签名字;如果是一个class就得是>.class名字
driver.find_element_by_css_selector(‘#id_Col_Pos>option’)[1].click()#[1]表示要选择option中的第2个元素,从0开始。
实例化driver代码如下:
import selenium import webdriver
driver=webdriver.Chrome()
driver.set_window_size(800)#设置窗口大小
**
二、如何读excel表
**
import xlrd
def info()
read_file=xlrd.open_workbook('123.xls')
sheet=read_file.sheet_by_index(0) #通过工作表索引读取第一个工作表
#print(sheet.ncols) #打印工作表有几列
#print(sheet.nrows)#打印工作表有几行
user=sheet.col_values(0) #将第一列的值赋给用户名
pwd=sheet.col_values(1)
info()