{"id":3501,"date":"2025-01-16T19:25:41","date_gmt":"2025-01-16T19:25:41","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/16\/gestures-slider-resizable-elements-in-playwright-java\/"},"modified":"2025-01-16T19:25:41","modified_gmt":"2025-01-16T19:25:41","slug":"gestures-slider-resizable-elements-in-playwright-java","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2025\/01\/16\/gestures-slider-resizable-elements-in-playwright-java\/","title":{"rendered":"Gestures (Slider, Resizable elements) in Playwright Java"},"content":{"rendered":"<p><html><body><\/p>\n<section class=\"tcb-post-content tcb-shortcode thrv_wrapper\" data-css=\"tve-u-16ec5d248bb\">\n<div class=\"tve_flt tcb-style-wrap\" id=\"tve_flt\">\n<div class=\"tve_shortcode_editor tar-main-content\" data-post-id=\"3501\" id=\"tve_editor\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><em>In this blog we will be utilizing Playwright Java to handle gestures.<\/em><\/p>\n<div class=\"code-block code-block-2\" style=\"margin: 8px auto; text-align: center; display: block; clear: both;\">\n<p><!-- horizontal responsive 2 --><br \/>\n<ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-3231318496783163\" data-ad-format=\"auto\" data-ad-slot=\"2788468763\" data-full-width-responsive=\"true\" style=\"display:block\"><\/ins>\n<\/div>\n<p><strong>Topics that we will cover:<\/strong><\/p>\n<ul class=\"\">\n<li>Handle sliders<\/li>\n<li>Handle resizable element<\/li>\n<li>Source code (slider)<\/li>\n<li>Source code (resizable)<\/li>\n<\/ul>\n<p><strong>Handle sliders<\/strong><\/p>\n<p>To understand sliders, go to <a class=\"\" href=\"https:\/\/jqueryui.com\/resources\/demos\/slider\/default.html\" rel=\"noopener\" style=\"outline: none;\" target=\"_blank\">https:\/\/jqueryui.com\/resources\/demos\/slider\/default.html<\/a>\u00a0<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19470974d06\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3504\" data-css=\"tve-u-19470975fdc\" data-height=\"94\" data-id=\"3504\" data-init-height=\"196\" data-init-width=\"1198\" data-width=\"577\" decoding=\"async\" height=\"94\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.57.55\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 196;\" title=\"Screenshot 2025-01-17 at 12.57.55\u202fAM\" width=\"577\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0 As can be seen above, there is a slider that we can move to right and left on the horizontal x-axis.<\/p>\n<p>Let us inspect the slider and copy the xpath<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-19470982c9f\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3505\" data-css=\"tve-u-194709840a5\" data-height=\"263\" data-id=\"3505\" data-init-height=\"586\" data-init-width=\"1198\" data-width=\"537\" decoding=\"async\" height=\"263\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.58.44\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 586;\" title=\"Screenshot 2025-01-17 at 12.58.44\u202fAM\" width=\"537\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Thus we can locate this element as shown below<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1947098e83e\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3506\" data-css=\"tve-u-1947098fdd2\" data-height=\"438\" data-id=\"3506\" data-init-height=\"1034\" data-init-width=\"1198\" data-width=\"507\" decoding=\"async\" height=\"438\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-12.59.34\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 1034;\" title=\"Screenshot 2025-01-17 at 12.59.34\u202fAM\" width=\"507\"\/><\/span><\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-1947099a2ca\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3507\" data-css=\"tve-u-1947099ce28\" data-height=\"393\" data-id=\"3507\" data-init-height=\"936\" data-init-width=\"1198\" data-width=\"503\" decoding=\"async\" height=\"393\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.00.26\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 936;\" title=\"Screenshot 2025-01-17 at 1.00.26\u202fAM\" width=\"503\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>We will than fire an event called as &#8216;mouse down&#8217; to move the mouse<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194709b1180\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3508\" data-css=\"tve-u-194709b22bc\" data-height=\"84\" data-id=\"3508\" data-init-height=\"180\" data-init-width=\"1198\" data-width=\"561\" decoding=\"async\" height=\"84\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.01.59\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 180;\" title=\"Screenshot 2025-01-17 at 1.01.59\u202fAM\" width=\"561\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0We will than move the slider to 600 pixels on the x-axis. However y-axis will always be 0. So we can simply copy the slider.boundingBox() code for y-axis as is<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194709b8e4c\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3509\" data-css=\"tve-u-194709ba028\" data-height=\"116\" data-id=\"3509\" data-init-height=\"210\" data-init-width=\"1198\" data-width=\"663\" decoding=\"async\" height=\"116\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.02.36\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 210;\" title=\"Screenshot 2025-01-17 at 1.02.36\u202fAM\" width=\"663\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Finally we will release the mouse<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194709c1ed5\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3510\" data-css=\"tve-u-194709c3592\" data-height=\"573\" data-id=\"3510\" data-init-height=\"1372\" data-init-width=\"1198\" data-width=\"500\" decoding=\"async\" height=\"573\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.03.09\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 1372;\" title=\"Screenshot 2025-01-17 at 1.03.09\u202fAM\" width=\"500\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p><strong>Handle resizable element<\/strong><\/p>\n<p>Let us now go to <a class=\"\" href=\"https:\/\/jqueryui.com\/resources\/demos\/resizable\/default.html\" rel=\"noopener\" style=\"outline: none;\" target=\"_blank\">https:\/\/jqueryui.com\/resources\/demos\/resizable\/default.html<\/a>\u00a0<\/p>\n<p>We see a re-sizable element that we can drag horizontally (x-axis) and vertically as well (y-axis)<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194709cd9f3\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3511\" data-css=\"tve-u-194709cec92\" data-height=\"526\" data-id=\"3511\" data-init-height=\"1172\" data-init-width=\"1198\" data-width=\"538\" decoding=\"async\" height=\"526\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.03.53\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 1172;\" title=\"Screenshot 2025-01-17 at 1.03.53\u202fAM\" width=\"538\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>Since we can resize vertically as well, let us add 300 pixels to y-axis<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194709d621b\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3512\" data-css=\"tve-u-194709d77e5\" data-height=\"73\" data-id=\"3512\" data-init-height=\"140\" data-init-width=\"1198\" data-width=\"622\" decoding=\"async\" height=\"73\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.04.38\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 140;\" title=\"Screenshot 2025-01-17 at 1.04.38\u202fAM\" width=\"622\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0So we have made changes to only 3 lines, see below<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194709ddd14\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3513\" data-css=\"tve-u-194709df1e8\" data-height=\"305\" data-id=\"3513\" data-init-height=\"652\" data-init-width=\"1198\" data-width=\"561\" decoding=\"async\" height=\"305\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.05.09\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 652;\" title=\"Screenshot 2025-01-17 at 1.05.09\u202fAM\" width=\"561\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0Execute.\u00a0<\/p>\n<p>Notice below that resizable element moves the desired number of pixels to x and y-axis<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve_image_caption\" data-css=\"tve-u-194709e66a0\" style=\"\"><span class=\"tve_image_frame\"><img alt=\"\" class=\"tve_image wp-image-3514\" data-css=\"tve-u-194709e7a5a\" data-height=\"411\" data-id=\"3514\" data-init-height=\"792\" data-init-width=\"1198\" data-width=\"622\" decoding=\"async\" height=\"411\" loading=\"lazy\" src=\"\/blog\/wp-content\/uploads\/2025\/01\/Screenshot-2025-01-17-at-1.05.43\u202fAM.png\" style=\"aspect-ratio: auto 1198 \/ 792;\" title=\"Screenshot 2025-01-17 at 1.05.43\u202fAM\" width=\"622\"\/><\/span><\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>\u00a0So this is how we can handle slider and resizable elements using playwright java.<\/p>\n<p><strong>Source code (sliders)<\/strong><\/p>\n<p><strong>package<\/strong> com.rsa.playwrightjava;<\/p>\n<p><\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Browser;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Locator;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Page;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/p>\n<p><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog29_Slider {<\/p>\n<p><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>static<\/strong><br \/>\n<strong>void<\/strong> main(String[] args) {<\/p>\n<p><\/p>\n<p>Playwright playwright = Playwright.<em>create<\/em>();<\/p>\n<p>Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));<\/p>\n<p><\/p>\n<p>Page page = browser.newPage();<\/p>\n<p>page.navigate(&#8220;https:\/\/jqueryui.com\/resources\/demos\/slider\/default.html&#8221;);<\/p>\n<p><strong>try<\/strong> {<\/p>\n<p>Thread.<em>sleep<\/em>(3000);<\/p>\n<p>} <strong>catch<\/strong> (InterruptedException e) {<\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>Locator slider = page.locator(&#8220;\/\/*[@id=&#8221;slider&#8221;]\/span&#8221;);<\/p>\n<p>page.mouse().move(slider.boundingBox().x + slider.boundingBox().width\/2, slider.boundingBox().y+slider.boundingBox().height\/2); \/\/to move mouse to middle of this element<\/p>\n<p>page.mouse().down(); \/\/to move the mouse<\/p>\n<p>page.mouse().move(slider.boundingBox().x+ 600, slider.boundingBox().y+slider.boundingBox().height\/2);<\/p>\n<p>page.mouse().up(); \/\/release the mouse<\/p>\n<p>page.pause();<\/p>\n<p>page.close();<\/p>\n<p>playwright.close();<\/p>\n<p><\/p>\n<p>}<\/p>\n<p><\/p>\n<p>}<\/p>\n<p><\/p>\n<p><strong>Source code (resizable)<\/strong><\/p>\n<p><strong>package<\/strong> com.rsa.playwrightjava;<\/p>\n<p><\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Browser;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.BrowserType;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Locator;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Page;<\/p>\n<p><strong>import<\/strong> com.microsoft.playwright.Playwright;<\/p>\n<p><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>class<\/strong> Blog29_Resizable {<\/p>\n<p><\/p>\n<p><strong>public<\/strong><br \/>\n<strong>static<\/strong><br \/>\n<strong>void<\/strong> main(String[] args) {<\/p>\n<p><\/p>\n<p>Playwright playwright = Playwright.<em>create<\/em>();<\/p>\n<p>Browser browser = playwright.chromium().launch(<strong>new<\/strong> BrowserType.LaunchOptions().setHeadless(<strong>false<\/strong>));<\/p>\n<p><\/p>\n<p>Page page = browser.newPage();<\/p>\n<p>page.navigate(&#8220;https:\/\/jqueryui.com\/resources\/demos\/resizable\/default.html&#8221;);<\/p>\n<p><strong>try<\/strong> {<\/p>\n<p>Thread.<em>sleep<\/em>(3000);<\/p>\n<p>} <strong>catch<\/strong> (InterruptedException e) {<\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>\/\/locate slider element<\/p>\n<p>Locator slider = page.locator(&#8220;\/\/*[@id=&#8221;resizable&#8221;]\/div[3]&#8221;);\u00a0<\/p>\n<p>\/\/to move mouse to middle of slider element<\/p>\n<p>page.mouse().move(slider.boundingBox().x + slider.boundingBox().width\/2, slider.boundingBox().y+slider.boundingBox().height\/2);\u00a0<\/p>\n<p>\/\/to move the mouse<\/p>\n<p>page.mouse().down();\u00a0<\/p>\n<p>\/\/move mouse to 300 pixels horizontal and vertical\u00a0<\/p>\n<p>page.mouse().move(slider.boundingBox().x + 300, slider.boundingBox().y + 300);<\/p>\n<p>\/\/release the mouse<\/p>\n<p>page.mouse().up();\u00a0<\/p>\n<p>page.pause();<\/p>\n<p>page.close();<\/p>\n<p>playwright.close();<\/p>\n<p><\/p>\n<p>}<\/p>\n<p><\/p>\n<p>}<\/p>\n<p><\/p>\n<p>Thanks.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tcb_flag\" style=\"display: none\"><\/div>\n<\/section>\n<p><\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we will be utilizing Playwright Java to handle gestures. Topics that we will cover: Handle sliders Handle resizable element Source code (slider) Source code (resizable) Handle sliders To understand sliders, go to https:\/\/jqueryui.com\/resources\/demos\/slider\/default.html\u00a0 \u00a0 As can be seen above, there is a slider that we can move to right and left on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-3501","post","type-post","status-publish","format-standard","hentry","category-java","category-playwright","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=3501"}],"version-history":[{"count":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3501\/revisions"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}