【问题标题】:Is there a possibility to select text by mouse double click and drag the selectet text by mouse to another webElement in Selenium Webdriver Python是否有可能通过鼠标双击选择文本并通过鼠标将所选文本拖动到 Selenium Webdriver Python 中的另一个 webElement
【发布时间】:2020-06-10 07:25:41
【问题描述】:

是否有可能通过鼠标双击选择文本并通过鼠标将选定文本拖动到 Selenium Webdriver Python 中的另一个 webElement

【问题讨论】:

  • 为什么要DragnDrop 而不是send_keys()
  • 因为我正在致力于自动化网络表单填充,第一个字段无法复制,第二个字段必须填写第一个字段的数据(它是验证码)

标签: python selenium selenium-webdriver


【解决方案1】:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


driver = webdriver.Chrome()
driver.get("your site")

source = driver.find_element_by_xpath('your element to drag')
destination = driver.find_element_by_xpath('element to drag to')

ActionChains(driver).drag_and_drop(source= source, target= destination).perform()

【讨论】:

  • Thanx Manish,但是我想移动真正的鼠标,所以我使用“MousePos”来定位光标的坐标,并使用“pyautogui”来完成这项工作,并且成功了跨度>
  • pyautogui.moveTo(242, 640) pyautogui.drag(70, 0, duration=0.35) # move right pyautogui.drag(0, 82, duration=0.45) # move down
猜你喜欢
  • 2017-05-27
  • 1970-01-01
  • 1970-01-01
  • 2010-11-13
  • 1970-01-01
  • 2017-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多