selenium-行为链-ActionChains-0223

行为链

在这里插入图片描述

在这里插入图片描述

思路:

  • 创建一个行为对象,需要浏览器对象
  • 行为对象设定一些操作的预设
  • 行为对象执行计划

演练代码

在这里插入图片描述
演练代码有多余的操作

使用注意:

标签要先提前找到

move_to_element(标签)

相当于选中

实操代码

from selenium import webdriver

# 获得驱动程序
from selenium.webdriver import ActionChains

driver = webdriver.Chrome()
# 请求网址的定义
url = 'https://www.baidu.com/'
# 发起请求
driver.get(url)

# 找到文本输入框
inputBox = driver.find_element_by_xpath('//*[@id="kw"]')

# 找到按钮
submitBtn = driver.find_element_by_xpath('//*[@id="su"]')

# 行为链
action = ActionChains(driver)
action.move_to_element(inputBox)
action.send_keys('java')
action.move_to_element(submitBtn)
action.click()
action.perform()

在这里插入图片描述

发布了941 篇原创文章 · 获赞 44 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/ifubing/article/details/104467586