Home > Back-end >  How to drag and drop the element using python selenium
How to drag and drop the element using python selenium

Time:10-12

Here I need to automate and reduce the bar to 50% that is I should make it to move into the middle.

Slider Image

Html for whole slider

<div class="LayerCategoryDetailSidebar_opacityBox__3Lw7t"><div class="LayerCategoryDetailSidebar_opacityRow__hKVms"><div class="rc-slider ghSlider"><div class="rc-slider-rail"></div><div class="rc-slider-track" style="left: 0%; right: auto; width: 48%;"></div><div class="rc-slider-step"></div><div tabindex="0" class="rc-slider-handle" role="slider" aria-valuemin="0" aria-valuemax="1" aria-valuenow="0.48" aria-disabled="false" style="left: 48%; right: auto; transform: translateX(-50%);"></div><div class="rc-slider-mark"></div></div><div class="LayerCategoryDetailSidebar_categorySwitch__HfcuU" style="position: relative; display: inline-block; text-align: left; opacity: 1; direction: ltr; border-radius: 12px; transition: opacity 0.25s ease 0s; touch-action: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); user-select: none;"><div class="react-switch-bg" style="height: 24px; width: 40px; margin: 0px; position: relative; background: rgb(243, 119, 53); border-radius: 12px; cursor: pointer; transition: background 0.25s ease 0s;"></div><div class="react-switch-handle" style="height: 22px; width: 22px; background: rgb(255, 255, 255); display: inline-block; cursor: pointer; border-radius: 50%; position: absolute; transform: translateX(17px); top: 1px; outline: 0px; border: 0px; transition: background-color 0.25s ease 0s, transform 0.25s ease 0s, box-shadow 0.15s ease 0s;"></div><input type="checkbox" role="switch" checked="" style="border: 0px; clip: rect(0px, 0px, 0px, 0px); height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; width: 1px;"></div></div><div class="LayerCategoryDetailSidebar_opacityInfo__1bBk3">Transparency</div></div>

Please help me with python selenium.

Need Output As

i.e Round button reduced into half.

CodePudding user response:

You can combine the selenium automation with pyautogui, in that way you'll be able to control mouse movements like dragging and more.

You can read more about the mouse functions in PyAutoGUI website in this link:

Mouse Control Fucntions - PyAutoGUI

CodePudding user response:

I tried to solve it in this way, Thanks for the help.

ActionChains(driver).click_and_hold(slider_element).move_by_offset(-100, 0).release().perform()
  • Related