1、准备html文件

  首先我们需要准备一个鼠标滑动的html文件,用来演示鼠标滑动的效果,注意需要将我们的html文件放在自己的服务器上,

这样我们才能够通过selenium来进行验证。html文件如下:

<html>
<head>
  <meta charset="utf-8" />
  <style>
    body {
  margin: 0;
  padding: 0;
}

input{
  appearance:none;
  -moz-appearance:none;
  -webkit-appearance:none;
  background: none;
  border:none;
}

.wrap{
  margin: 200px 0 0 200px;
}

.box {
  position: relative;
  width: 200px;
  height: 30px;
  border-radius: 20px;
  background: #686B69;
  line-height: 30px;
  overflow: hidden;
  margin-bottom: 40px;
  color: #fff;
  font-size: 12px;
}

.btn {
  position: absolute;
  top: 0;
  left: 0;
  height: 30px;
  width: 30px;
  background: #0c7;
  border-radius: 20px;
  text-align: center;
}

.tips {
  text-align: center;
}

#submit{
  line-height: 28px;
  border-radius: 3px;
  background: #0c7;
  width: 200px;
  text-align: center;
  color: #fff;
}
  </style>
</head>
<body>
<div class="wrap">
  <div class="box">
    <div class="btn" id="dragEle"></div>
    <div class="tips">拖动滑块验证<<</div>
  </div>
 <input type="button" value="提交验证" id="submit" />
</div>
<script src="/UploadFiles/2021-04-08/jquery-3.1.1.min.js">

2、使用selenium进行鼠标拖拽操作,具体代码如下:

from selenium import webdriver
import unittest
from selenium.webdriver import ActionChains
import time
 
 
url = 'http://192.168.62.9:1234/easytest/tt'
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
driver.get(url)
driver.maximize_window()
 # 获取第一,二,三能拖拽的元素
drag1 = driver.find_element_by_id('dragEle')
 
# 创建一个新的ActionChains,将webdriver实例对driver作为参数值传入,然后通过WenDriver实例执行用户动作
action_chains = ActionChains(driver)
# 将页面上的第一个能被拖拽的元素拖拽到第二个元素位置
# 将页面上的第三个能拖拽的元素,向右下拖动10个像素,共拖动5次
action_chains.drag_and_drop_by_offset(drag1, 208, 0).perform()
time.sleep(5)
driver.quit()

以上就是python 基于selenium实现鼠标拖拽功能的详细内容,更多关于python 鼠标拖拽的资料请关注其它相关文章!

标签:
python,selenium,python,鼠标拖拽

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com

评论“python 基于selenium实现鼠标拖拽功能”

暂无“python 基于selenium实现鼠标拖拽功能”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。