How to use drag_and_drop method in Playwright Python

Best Python code snippet using playwright-python

test_parsons.py

Source:test_parsons.py Github

copy

Full Screen

...23 assert message.get_attribute("style") == "display: none;"24 checkme.click()25 assert message.get_attribute("class") == "alert alert-danger"26 reset.click()27 ActionChains(selenium_utils_get.driver).drag_and_drop(28 source.find_element_by_id("parsons-1-block-3"), answer29 ).perform()30 ActionChains(selenium_utils_get.driver).drag_and_drop(31 source.find_element_by_id("parsons-1-block-2"),32 answer.find_element_by_id("parsons-1-block-3"),33 ).perform()34 ActionChains(selenium_utils_get.driver).drag_and_drop(35 source.find_element_by_id("parsons-1-block-1"),36 answer.find_element_by_id("parsons-1-block-2"),37 ).perform()38 ActionChains(selenium_utils_get.driver).drag_and_drop(39 source.find_element_by_id("parsons-1-block-0"),40 answer.find_element_by_id("parsons-1-block-1"),41 ).perform()42 ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(43 answer.find_element_by_id("parsons-1-block-0"), -50, 044 ).perform()45 wait_for_animation(selenium_utils_get, "#parsons-1-block-0")46 checkme.click()47 message = selenium_utils_get.driver.find_element_by_id("parsons-1-message")48 assert message.get_attribute("class") == "alert alert-info"49 # check that reset works50 reset.click()51 blocks = source.find_elements_by_class_name("block")52 assert len(blocks) == 553def test_help(selenium_utils_get):54 selenium_utils_get.wait_until_ready("test_parsons_1")55 source = selenium_utils_get.driver.find_element_by_id("parsons-1-source")56 answer = selenium_utils_get.driver.find_element_by_id("parsons-1-answer")57 reset = selenium_utils_get.driver.find_element_by_id("parsons-1-reset")58 reset.click()59 checkme = selenium_utils_get.driver.find_element_by_id("parsons-1-check")60 # click help, should cause pop up61 helpBtn = selenium_utils_get.driver.find_element_by_id("parsons-1-help")62 helpBtn.click()63 assert wait_and_close_alert(selenium_utils_get)64 # try three distinct full attempts => help should cause pop up then cause stuff to happen65 ActionChains(selenium_utils_get.driver).drag_and_drop(66 source.find_element_by_id("parsons-1-block-4"), answer67 ).perform()68 ActionChains(selenium_utils_get.driver).drag_and_drop(69 source.find_element_by_id("parsons-1-block-2"),70 answer.find_element_by_id("parsons-1-block-4"),71 ).perform()72 ActionChains(selenium_utils_get.driver).drag_and_drop(73 source.find_element_by_id("parsons-1-block-1"),74 answer.find_element_by_id("parsons-1-block-2"),75 ).perform()76 ActionChains(selenium_utils_get.driver).drag_and_drop(77 source.find_element_by_id("parsons-1-block-0"),78 answer.find_element_by_id("parsons-1-block-1"),79 ).perform()80 wait_for_animation(selenium_utils_get, "#parsons-1-block-0")81 checkme.click()82 reset.click()83 ActionChains(selenium_utils_get.driver).drag_and_drop(84 source.find_element_by_id("parsons-1-block-2"), answer85 ).perform()86 ActionChains(selenium_utils_get.driver).drag_and_drop(87 source.find_element_by_id("parsons-1-block-4"),88 answer.find_element_by_id("parsons-1-block-2"),89 ).perform()90 ActionChains(selenium_utils_get.driver).drag_and_drop(91 source.find_element_by_id("parsons-1-block-1"),92 answer.find_element_by_id("parsons-1-block-2"),93 ).perform()94 ActionChains(selenium_utils_get.driver).drag_and_drop(95 source.find_element_by_id("parsons-1-block-0"),96 answer.find_element_by_id("parsons-1-block-1"),97 ).perform()98 wait_for_animation(selenium_utils_get, "#parsons-1-block-0")99 checkme.click()100 reset.click()101 ActionChains(selenium_utils_get.driver).drag_and_drop(102 source.find_element_by_id("parsons-1-block-2"), answer103 ).perform()104 ActionChains(selenium_utils_get.driver).drag_and_drop(105 source.find_element_by_id("parsons-1-block-4"),106 answer.find_element_by_id("parsons-1-block-2"),107 ).perform()108 ActionChains(selenium_utils_get.driver).drag_and_drop(109 source.find_element_by_id("parsons-1-block-0"),110 answer.find_element_by_id("parsons-1-block-4"),111 ).perform()112 ActionChains(selenium_utils_get.driver).drag_and_drop(113 source.find_element_by_id("parsons-1-block-1"),114 answer.find_element_by_id("parsons-1-block-0"),115 ).perform()116 wait_for_animation(selenium_utils_get, "#parsons-1-block-1")117 checkme.click()118 assert wait_and_close_alert(selenium_utils_get)119 helpBtn.click() # remove the incorrect block120 assert wait_and_close_alert(selenium_utils_get)121 wait_for_animation(selenium_utils_get, "#parsons-1-block-4")122 b4 = source.find_element_by_id("parsons-1-block-4")123 assert b4.get_attribute("class") == "block disabled"124 helpBtn.click() # Combine blocks125 assert wait_and_close_alert(selenium_utils_get)126 wait_for_animation(selenium_utils_get, "#parsons-1-block-3")127 l5 = answer.find_element_by_id("parsons-1-line-5")128 # There seems to be a timing issue -- a bit of delay makes this pass.129 time.sleep(0.1)130 assert l5.get_attribute("class") == "prettyprint lang-py"131 try:132 selenium_utils_get.driver.find_element_by_id("parsons-1-block-3")133 except NoSuchElementException:134 pass135 else:136 assert False137 b2 = answer.find_element_by_id("parsons-1-block-2")138 l3 = b2.find_element_by_id("parsons-1-line-3")139 l4 = b2.find_element_by_id("parsons-1-line-4")140 l5 = b2.find_element_by_id("parsons-1-line-5")141 assert l3142 assert l4143 assert l5144 # Help is finished helping145 wait_for_animation(selenium_utils_get, "#parsons-1-block-2")146 answer_initial = answer.get_attribute("innerHTML")147 source_initial = source.get_attribute("innerHTML")148 helpBtn.click()149 assert wait_and_close_alert(selenium_utils_get)150 answer_after = answer.get_attribute("innerHTML")151 assert answer_initial == answer_after152 source_after = source.get_attribute("innerHTML")153 assert source_initial == source_after154def test_numbering(selenium_utils_get):155 selenium_utils_get.wait_until_ready("test_parsons_2")156 # right label block157 rlb = selenium_utils_get.driver.find_element_by_id("parsons-2-block-1")158 assert len(rlb.find_elements_by_class_name("labels")) == 1 # has label159 assert len(rlb.find_elements_by_class_name("lines")) == 1 # has lines160 children = rlb.find_elements_by_xpath("*")161 assert "lines" in children[0].get_attribute("class").split()162 assert "labels" in children[1].get_attribute("class").split()163 # label on right164 # left label block165 llb = selenium_utils_get.driver.find_element_by_id("parsons-3-block-1")166 assert len(llb.find_elements_by_class_name("labels")) == 1 # has label167 assert len(llb.find_elements_by_class_name("lines")) == 1 # has lines168 children = llb.find_elements_by_xpath("*")169 assert "lines" in children[1].get_attribute("class").split()170 assert "labels" in children[0].get_attribute("class").split()171 # label on left172 # no label block173 nlb = selenium_utils_get.driver.find_element_by_id("parsons-4-block-1")174 assert len(nlb.find_elements_by_class_name("labels")) == 0 # no label175 assert len(nlb.find_elements_by_class_name("lines")) == 1 # has lines176def test_indentation(selenium_utils_get):177 selenium_utils_get.wait_until_ready("test_parsons_1")178 source = selenium_utils_get.driver.find_element_by_id("parsons-1-source")179 answer = selenium_utils_get.driver.find_element_by_id("parsons-1-answer")180 reset = selenium_utils_get.driver.find_element_by_id("parsons-1-reset")181 reset.click()182 checkme = selenium_utils_get.driver.find_element_by_id("parsons-1-check")183 # try three distinct full attempts => help should cause pop up then cause stuff to happen184 ActionChains(selenium_utils_get.driver).drag_and_drop(185 source.find_element_by_id("parsons-1-block-4"), answer186 ).perform()187 ActionChains(selenium_utils_get.driver).drag_and_drop(188 source.find_element_by_id("parsons-1-block-2"),189 answer.find_element_by_id("parsons-1-block-4"),190 ).perform()191 ActionChains(selenium_utils_get.driver).drag_and_drop(192 source.find_element_by_id("parsons-1-block-1"),193 answer.find_element_by_id("parsons-1-block-2"),194 ).perform()195 ActionChains(selenium_utils_get.driver).drag_and_drop(196 source.find_element_by_id("parsons-1-block-0"),197 answer.find_element_by_id("parsons-1-block-1"),198 ).perform()199 wait_for_animation(selenium_utils_get, "#parsons-1-block-0")200 checkme.click()201 reset.click()202 ActionChains(selenium_utils_get.driver).drag_and_drop(203 source.find_element_by_id("parsons-1-block-2"), answer204 ).perform()205 ActionChains(selenium_utils_get.driver).drag_and_drop(206 source.find_element_by_id("parsons-1-block-4"),207 answer.find_element_by_id("parsons-1-block-2"),208 ).perform()209 ActionChains(selenium_utils_get.driver).drag_and_drop(210 source.find_element_by_id("parsons-1-block-1"),211 answer.find_element_by_id("parsons-1-block-2"),212 ).perform()213 ActionChains(selenium_utils_get.driver).drag_and_drop(214 source.find_element_by_id("parsons-1-block-0"),215 answer.find_element_by_id("parsons-1-block-1"),216 ).perform()217 wait_for_animation(selenium_utils_get, "#parsons-1-block-0")218 checkme.click()219 reset.click()220 ActionChains(selenium_utils_get.driver).drag_and_drop(221 source.find_element_by_id("parsons-1-block-3"), answer222 ).perform()223 ActionChains(selenium_utils_get.driver).drag_and_drop(224 source.find_element_by_id("parsons-1-block-2"),225 answer.find_element_by_id("parsons-1-block-3"),226 ).perform()227 ActionChains(selenium_utils_get.driver).drag_and_drop(228 source.find_element_by_id("parsons-1-block-1"),229 answer.find_element_by_id("parsons-1-block-2"),230 ).perform()231 ActionChains(selenium_utils_get.driver).drag_and_drop(232 source.find_element_by_id("parsons-1-block-0"),233 answer.find_element_by_id("parsons-1-block-1"),234 ).perform()235 ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(236 answer.find_element_by_id("parsons-1-block-0"), -50, 0237 ).perform()238 ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(239 answer.find_element_by_id("parsons-1-block-1"), -50, 0240 ).perform()241 ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(242 answer.find_element_by_id("parsons-1-block-2"), -50, 0243 ).perform()244 ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(245 answer.find_element_by_id("parsons-1-block-3"), -50, 0...

Full Screen

Full Screen

pymouse_utils.py

Source:pymouse_utils.py Github

copy

Full Screen

...36def double_click(pos):37 mouse.click(pos[0], pos[1])38 mouse.click(pos[0], pos[1])39# double_click(pos=(400, 10))40def drag_and_drop(from_pos, to_pos, speed=None, button=1):41 """Drag and drop movement42 The function is doing the hole motion interpolated if speed is not None. After reaching the from_pos the the mouse43 is pressed and at the target position the mouse is released44 """45 # print "START drag_and_drop"46 move(target_pos=from_pos, speed=speed)47 # print "position", mouse.position()48 # print "PRESS: ", from_pos49 mouse.press(x=from_pos[0], y=from_pos[1], button=button)50 time.sleep(TIME_STEP*10)51 move(target_pos=to_pos, speed=speed)52 # print "position", mouse.position()53 # print "RELEASE: ", to_pos54 time.sleep(TIME_STEP*10)55 mouse.release(x=to_pos[0], y=to_pos[1], button=button)56 # print "STOP drag_and_drop"57# time.sleep(3)58# input_pos = mouse.position()59# print "### INIT", input_pos60# # drag_and_drop(from_pos=(1200, 10), to_pos=(2000, 100))61# mouse.move(1200, 530)62# # input_pos63# drag_and_drop(from_pos=input_pos, to_pos=(1600, 530), speed=500)64# time.sleep(1)65# mouse.move(2000, 530)66# # drag_and_drop(from_pos=(1500, 530), to_pos=(1600, 530), speed=500)67# drag_and_drop(from_pos=(1600, 530), to_pos=(1500, 530), speed=500)68# print pymouse...

Full Screen

Full Screen

webBrowser_DD.py

Source:webBrowser_DD.py Github

copy

Full Screen

...14time.sleep(1)15source = driver.find_element_by_xpath('//*[@id="box1"]')16destination = driver.find_element_by_xpath('//*[@id="box101"]')17actions = ActionChains(driver)18actions.drag_and_drop(source, destination).perform()19time.sleep(1)20source = driver.find_element_by_xpath('//*[@id="box2"]')21destination = driver.find_element_by_xpath('//*[@id="box102"]')22actions = ActionChains(driver)23actions.drag_and_drop(source, destination).perform()24source = driver.find_element_by_xpath('//*[@id="box3"]')25destination = driver.find_element_by_xpath('//*[@id="box103"]')26actions = ActionChains(driver)27actions.drag_and_drop(source, destination).perform()28source = driver.find_element_by_xpath('//*[@id="box4"]')29destination = driver.find_element_by_xpath('//*[@id="box104"]')30actions = ActionChains(driver)31actions.drag_and_drop(source, destination).perform()32source = driver.find_element_by_xpath('//*[@id="box5"]')33destination = driver.find_element_by_xpath('//*[@id="box105"]')34actions = ActionChains(driver)35actions.drag_and_drop(source, destination).perform()36source = driver.find_element_by_xpath('//*[@id="box6"]')37destination = driver.find_element_by_xpath('//*[@id="box106"]')38actions = ActionChains(driver)39actions.drag_and_drop(source, destination).perform()40source = driver.find_element_by_xpath('//*[@id="box7"]')41destination = driver.find_element_by_xpath('//*[@id="box107"]')42actions = ActionChains(driver)...

Full Screen

Full Screen

selenium-drag-and-drop.py

Source:selenium-drag-and-drop.py Github

copy

Full Screen

...67was_source = driver.find_element_by_xpath('//*[@id="box3"]')8us_dest = driver.find_element_by_xpath('//*[@id="box103"]')9actions = ActionChains(driver)10actions.drag_and_drop(was_source, us_dest).perform()1112rom_source = driver.find_element_by_xpath('//*[@id="box6"]')13ita_dest = driver.find_element_by_xpath('//*[@id="box106"]')14actions = ActionChains(driver)15actions.drag_and_drop(rom_source, ita_dest).perform()1617seo_source = driver.find_element_by_xpath('//*[@id="box5"]')18sk_dest = driver.find_element_by_xpath('//*[@id="box105"]')19actions = ActionChains(driver)20actions.drag_and_drop(seo_source, sk_dest).perform()2122osl_source = driver.find_element_by_xpath('//*[@id="box1"]')23nor_dest = driver.find_element_by_xpath('//*[@id="box101"]')24actions = ActionChains(driver)25actions.drag_and_drop(osl_source, nor_dest).perform()2627mad_source = driver.find_element_by_xpath('//*[@id="box7"]')28spa_dest = driver.find_element_by_xpath('//*[@id="box107"]')29actions = ActionChains(driver)30actions.drag_and_drop(mad_source, spa_dest).perform()3132cop_source = driver.find_element_by_xpath('//*[@id="box4"]')33den_dest = driver.find_element_by_xpath('//*[@id="box104"]')34actions = ActionChains(driver)35actions.drag_and_drop(cop_source, den_dest).perform()3637sto_source = driver.find_element_by_xpath('//*[@id="box2"]')38swe_dest = driver.find_element_by_xpath('//*[@id="box102"]')39actions = ActionChains(driver)40actions.drag_and_drop(sto_source, swe_dest).perform()41 ...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful