#-*-coding:utf-8-*-from selenium import webdriverfrom time import sleepfrom selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Firefox() url = "https://www.baidu.com/"# url = "http://www.cnblogs.com/yoyoketang/"driver.get(url) """属性定位 一 """# #通过id# driver.find_element_by_css_selector("#kw").send_keys(u"博客园")# #通过class# driver.find_element_by_css_selector(".s_ipt").send_keys(u"博客园")#通过标签 数量过多的情况下需要增加标签过滤# driver.find_element_by_css_selector("span>input:nth-child(2)").send_keys(u"博客园") # #其他属性# driver.find_element_by_css_selector("[name = ‘wd‘]").send_keys(u"博客园")# driver.find_element_by_css_selector("[autocomplete = ‘off‘]").send_keys(u"博客园") """CSS 组合定位 二""""""父子关系的书写模式form.fm>span"""# driver.find_element_by_css_selector("form.fm>span>input.s_ipt").send_keys(u"博客园")# driver.find_element_by_css_selector("form.fm>span>input#kw").send_keys(u"博客园")#"""定位list 取某一个"""# print driver.find_element_by_css_selector(".mnav:nth-child(1)").text# driver.find_element_by_css_selector(".mnav:nth-child(1)").click() """CSS 逻辑运算,多条件组合定位-----没有定位到,不知道原因"""# driver.find_element_by_css_selector("[type=‘text‘][name=‘wd‘]").send_keys(u"博客园") sleep(3)driver.quit()
原文地址:https://www.cnblogs.com/tDayUp/p/8730093.html
时间: 2024-10-07 11:21:33