#案例:css选择器定位法
from selenium import webdriver # 导入webdriver包
import time
driver=webdriver.Chrome()
driver.maximize_window() # 最大化浏览器
driver.implicitly_wait(30)
driver.get("http://oss.52studyit.net/webzdh/zucea.html")
#演示id定位法#id名
# ele_userA=driver.find_element_by_css_selector("#userA")
# ele_userA.send_keys("张三")
##演示:class定位.class名
# ele_telA=driver.find_element_by_css_selector(".telA")
# ele_telA.send_keys("13760453683")
##演示:标签名定位 标签名
# ele_useA=driver.find_element_by_css_selector("input")
# ele_useA.send_keys("张三")
##演示:属性定位:类似[href] 标签名[属性名]
# ele_userA=driver.find_element_by_css_selector("input[name]")
# ele_userA.send_keys("张三")
##演示:属性定位:类似[href='xxx'] 标签名[属性名=属性值]
# ele_userA=driver.find_element_by_css_selector("input[name='userA']")
# ele_userA.send_keys("张三")
#演示:属性定位:类似[href^='xxx'] 以什么开头
# ele_reg=driver.find_element_by_css_selector("button[title^='加入']")
# ele_reg.click()
#演示:属性定位:类似[href$='xxx'] 以什么结尾
# ele_reg=driver.find_element_by_css_selector("button[title$='会员A']")
# ele_reg.click()
#演示:属性定位:类似[href*='xxx'] 包含内容
# ele_pwd=driver.find_element_by_css_selector("input[name*='word']")
# ele_pwd.send_keys("123456")
#演示:分组定位 标签名,
# eles=driver.find_elements_by_css_selector("input,a")
# ele_email=eles[3]
# ele_email.send_keys("851286894@qq.com")
#演示:子代选择器的使用
# ele_userA=driver.find_element_by_css_selector("p#p1 > input[id='userA']")
# ele_userA.send_keys("张三")
#演示:后代选择器的使用!
ele_reg=driver.find_element_by_css_selector("div#zc button[title='加入会员A']")
ele_reg.click()
##演示:同辈相邻兄弟: a + b
# ele_pwd=driver.find_element_by_css_selector("p#p1 + p > input")
# ele_pwd.send_keys("123456")
##演示:同辈兄弟:a ~ b
# eles=driver.find_elements_by_css_selector("p#p1 ~ p")
# ele_p3=eles[2]
# ele_email=ele_p3.find_element_by_css_selector("input")
# ele_email.send_keys("851286894@qq.com")
#演示::nth-child(N)
ele=driver.find_element_by_css_selector("div#zc > fieldset >p:nth-child(4) >input")
ele.send_keys("13760453683")
time.sleep(5)
driver.quit() # 关闭并退出浏览器