#!/usr/bin/env python
# -*- coding:utf-8 -*-
from selenium import webdriver
import time,os
# about:addons 火狐浏览器安装组件,访问的地址
# <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
#id
keys="selenium自动化"
url="https://www.baidu.com/"
# url="file:///D:/ideaSpace/autoProject/python_autotest/nicetime/webdriver/select01.html"
driver=webdriver.Firefox()
driver.get(url)
#id class 属性定位 #表示id .表示class 使用标签属性,表示为标签名
driver.find_element_by_css_selector("#kw").send_keys(keys)
driver.find_element_by_css_selector(".s_ipt").send_keys(keys)
#name属性定位
driver.find_element_by_css_selector("[name='wd']").send_keys(keys)
#其他属性定位
driver.find_element_by_css_selector("[autocomplete='off']").send_keys(keys)
# 标签与属性的组合来定位 id name class 其他属性
driver.find_element_by_css_selector("input#kw").send_keys(keys)
driver.find_element_by_css_selector("input[name='wd']").send_keys(keys)
driver.find_element_by_css_selector("input.s_ipt").send_keys(keys)
driver.find_element_by_css_selector("input[autocomplete='off']").send_keys(keys)
# <form name="f" id="form" action="/s" class="fm" onsubmit="javascript:F.call('ps/sug','pssubmit');">
# <span id="s_kw_wrap" class="bg s_ipt_wr quickdelete-wrap">
# <span class="soutu-btn"></span><input type="text" class="s_ipt" name="wd" id="kw" maxlength="100" autocomplete="off">
#用>表示层级关系 id name class
driver.find_element_by_css_selector("form#form>span>input").send_keys(keys)
driver.find_element_by_css_selector("form[name='f']>span>input").send_keys(keys)
driver.find_element_by_css_selector("form.fm>span>input").send_keys(keys)
#多属性组合
driver.find_element_by_css_selector("input[id='kw'][name='wd']").send_keys(keys)
#select01.html文件
# 下拉框选择形式
# <select id="status" class="form-control valid" onchange="" name="status">
# <option value=""></option>
# <option value="0">未审核</option>
# <option value="1">初审通过</option>
# <option value="2">复审通过</option>
# <option value="3">审核不通过</option>
# </select>
# 定位子元素 nth-child(n)
driver.find_element_by_css_selector("select#status>option:nth-child(4)").click()
time.sleep(3)
driver.quit()