from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver_path = r'D:\python\geckodriver-v0.23.0-win64\geckodriver.exe'
driver = webdriver.Firefox(executable_path=driver_path)
driver.get("https://www.baidu.com/")
inputTag = driver.find_element_by_id('kw')
sumbmitBtn = driver.find_element_by_xpath('//input[@id="su"]')
action = ActionChains(driver)
action.move_to_element(inputTag)
action.send_keys_to_element(inputTag,'python')
action.move_to_element(sumbmitBtn)
action.click(sumbmitBtn)
action.perform() # 执行行为动作
网友评论