Add username and password fill

This commit is contained in:
Mylloon 2023-05-14 01:44:11 +02:00
parent 81f8318e73
commit 85c20935c0
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 34 additions and 10 deletions

View file

@ -6,7 +6,7 @@ open Twitter
let start driver =
let name_driver = prepare driver in
let data_driver = run_process name_driver [] in
let session_id = get_session (* ~headless:false *) () in
let session_id = get_session ~headless:false () in
data_driver, session_id
;;

View file

@ -1,12 +1,12 @@
open Pusk.Net
open Pusk.Utils
let login_twitter ctx username _password =
let login_twitter ctx username password =
(* Navigate to login page and wait for page loaded*)
ignore (navigate ctx.session_id "https://twitter.com/i/flow/login");
Unix.sleep 5;
(* Find username input *)
let element_id =
let input_username =
match
find
ctx.session_id
@ -20,5 +20,27 @@ let login_twitter ctx username _password =
else List.nth l 0
in
(* Insert the username *)
send_keys ctx.session_id element_id username
send_keys ctx.session_id input_username username;
Unix.sleep 1;
send_keys ctx.session_id input_username Keys.return;
Unix.sleep 3;
(* Find password input *)
let input_password =
match
find
ctx.session_id
(XPath
"/html/body/div[1]/div/div/div[1]/div/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div/div[3]/div/label/div/div[2]/div[1]/input")
with
| [] -> raise (Any "Password input not found")
| _ as l ->
if List.length l > 1
then raise (Any "Too many element found as the password input")
else List.nth l 0
in
(* Insert password *)
send_keys ctx.session_id input_password password;
Unix.sleep 1;
send_keys ctx.session_id input_password Keys.return;
Unix.sleep 5
;;

View file

@ -113,10 +113,8 @@ let find session_id strategy =
;;
let send_keys session_id element_id username =
let response =
execute_post_request
ignore
(execute_post_request
(fmt "%s/element/%s/value" (driver session_id) element_id)
(Json.send_keys_payload username)
in
print_endline response
(Json.send_keys_payload username))
;;

View file

@ -17,3 +17,7 @@ let keys_to_typing str =
in
aux [] (String.length str)
;;
module Keys = struct
let return = "\\ue006"
end