From 9d0e2f6a7f7cec041024f616f5158e0945e96605 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 9 Mar 2024 16:13:52 +0100 Subject: [PATCH] since tweet issue (#3) --- bin/twitter.ml | 3 +++ lib/json.ml | 40 ++++++++++++++++++++++++++++++++++++++++ lib/net.ml | 7 +++++++ 3 files changed, 50 insertions(+) diff --git a/bin/twitter.ml b/bin/twitter.ml index 181c1ab..599f10b 100644 --- a/bin/twitter.ml +++ b/bin/twitter.ml @@ -151,6 +151,9 @@ let tweet ctx msg = | it :: [] -> it | _ -> raise (Any "Too many tweet button found") in + (* We need first to click somewhere on the page to be able to interact with it *) + click_somewhere ctx.session_id 800 200; + Unix.sleep 2; click ctx.session_id send_tweet_button; Unix.sleep 8 ;; diff --git a/lib/json.ml b/lib/json.ml index cfbfca8..676b0d9 100644 --- a/lib/json.ml +++ b/lib/json.ml @@ -52,3 +52,43 @@ let send_keys_payload text = (Yojson.Safe.to_string (`List (List.map (fun str -> `String str) (keys_to_typing text)))) ;; + +let send_left_click pos_x pos_y = + fmt + {| + { + "actions": [ + { + "type": "pointer", + "id": "mouse", + "parameters": { + "pointerType": "mouse" + }, + "actions": [ + { + "type": "pointerMove", + "origin": "viewport", + "x": %d, + "y": %d, + "duration": 0 + }, + { + "type": "pointerDown", + "button": 0 + }, + { + "type": "pause", + "duration": 100 + }, + { + "type": "pointerUp", + "button": 0 + } + ] + } + ] + } + |} + pos_x + pos_y +;; diff --git a/lib/net.ml b/lib/net.ml index 57cab53..026879b 100644 --- a/lib/net.ml +++ b/lib/net.ml @@ -153,6 +153,13 @@ let click session_id element_id = Json.empty) ;; +let click_somewhere session_id x y = + ignore + (execute_post_request + (fmt "%s/actions" (driver session_id)) + (Json.send_left_click x y)) +;; + let get_attribute session_id element_id attribute = let response = execute_get_request