click to profile

This commit is contained in:
Mylloon 2023-05-15 11:44:21 +02:00
parent d5a7c3d0ed
commit f04b3fa763
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 26 additions and 3 deletions

View file

@ -25,7 +25,8 @@ let main ctx =
| None, Some _ -> raise (Any "Username not set") | None, Some _ -> raise (Any "Username not set")
| Some _, None -> raise (Any "Password not set") | Some _, None -> raise (Any "Password not set")
in in
login_twitter ctx username password (Sys.getenv_opt "TWITTER_TOTP") login_twitter ctx username password (Sys.getenv_opt "TWITTER_TOTP");
go_to_profile ctx
;; ;;
let handler data (signal : int) = let handler data (signal : int) =

View file

@ -80,3 +80,16 @@ let login_twitter ctx username password secret =
then raise (Any "Too many elements found as 2FA input") then raise (Any "Too many elements found as 2FA input")
else inject_2fa ctx.session_id secret (List.nth l 0) else inject_2fa ctx.session_id secret (List.nth l 0)
;; ;;
let go_to_profile ctx =
let profile_button =
match find ctx.session_id (XPath "//a[@data-testid='AppTabBar_Profile_Link']") with
| [] -> raise (Any (fmt "Profile button not found"))
| _ as l ->
if List.length l > 1
then raise (Any "Too many profile button found")
else List.nth l 0
in
click ctx.session_id profile_button;
Unix.sleep 4
;;

View file

@ -1,5 +1,7 @@
open Utils open Utils
let empty = "{}"
let connection_payload headless = let connection_payload headless =
fmt fmt
{| {|

View file

@ -115,9 +115,16 @@ let find session_id strategy =
| _ -> raise (Any "wait_for_load | Invalid JSON") | _ -> raise (Any "wait_for_load | Invalid JSON")
;; ;;
let send_keys session_id element_id username = let send_keys session_id element_id data =
ignore ignore
(execute_post_request (execute_post_request
(fmt "%s/element/%s/value" (driver session_id) element_id) (fmt "%s/element/%s/value" (driver session_id) element_id)
(Json.send_keys_payload username)) (Json.send_keys_payload data))
;;
let click session_id element_id =
ignore
(execute_post_request
(fmt "%s/element/%s/click" (driver session_id) element_id)
Json.empty)
;; ;;