selenium 驱动浏览器

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome()
driver.get(‘https://www.baidu.com’)
driver.maximize_window()
WebDriverWait(driver, 15).until(lambda x: x.find_element_by_xpath(“.//*[@id=’kw’]”))
driver.find_element_by_xpath(“.//*[@id=’kw’]”).send_keys(“测试”)
driver.find_element_by_xpath(“.//*[@id=’su’]”).click()
WebDriverWait(driver, 15).until(lambda x: x.find_element_by_xpath(“.//*[@id=’1′]/h3/a”))
driver.close()
driver.quit()