1. 程式人生 > >css_selector定位,比xpath速度快,語法簡潔

css_selector定位,比xpath速度快,語法簡潔

driver.get("http://www.baidu.com")
#根據ID來定位
driver.find_element_by_css_selector('#kw').send_keys('selenium')
driver.find_element_by_id('su').click()
#根據class來定位
driver.find_element_by_css_selector('.s_ipt').send_keys('selenium')
driver.find_element_by_id('su').click()
#根據屬性來定位
driver.find_element_by_css_selector('[autocomplete="off"]').send_keys('python')