#!/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/"
driver=webdriver.Firefox()
driver.get(url)
#支持多个属性一起定位 and or not
driver.find_element_by_id("//*[@id='kw'] and [@autocomplete='off']").send_keys(keys)
#元素定位 id name class tagname text partialtext css xpath
driver.find_element_by_id("kw").send_keys(keys)
driver.find_element_by_name("wd").send_keys(keys)
driver.find_element_by_class_name("s_ipt").send_keys(keys)
driver.find_element_by_tag_name("input").send_keys(keys)
keys2="hao123"
keys3="123"
# <a href="https://www.hao123.com" name="tj_trhao123" class="mnav">hao123</a>
driver.find_element_by_link_text(keys2).click()
driver.find_element_by_partial_link_text(keys3).click()
driver.find_element_by_css_selector("input#kw").send_keys(keys)
driver.find_element_by_xpath("//*[@id='kw']").send_keys(keys)
time.sleep(5)
driver.close()