From da1c0c8298e82fd6a2ee697984a9f5ed266f6371 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 16 May 2023 03:11:40 +0200 Subject: [PATCH] use CSS selector for tweet area --- bin/twitter.ml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bin/twitter.ml b/bin/twitter.ml index e8eb9e0..706ca9e 100644 --- a/bin/twitter.ml +++ b/bin/twitter.ml @@ -152,23 +152,21 @@ let tweet ctx msg = in click ctx.session_id tweet_button; let tweet_area = - match find ctx.session_id (XPath "//div[@data-testid='tweetTextarea_0']") with + match find ctx.session_id (CSS "div[data-testid='tweetTextarea_0']") with + | [] -> raise (Any (fmt "Tweet area not found")) + | _ as l -> + if List.length l > 1 then raise (Any "Too many tweet areas found") else List.nth l 0 + in + send_keys ctx.session_id tweet_area msg; + Unix.sleep 2; + let send_tweet_button = + match find ctx.session_id (XPath "//div[@data-testid='tweetButton']") with | [] -> raise (Any (fmt "Tweet button not found")) | _ as l -> if List.length l > 1 then raise (Any "Too many tweet button found") else List.nth l 0 in - send_keys ctx.session_id tweet_area msg; - Unix.sleep 2; - let send_tweet_button = - match find ctx.session_id (XPath "//div[@data-testid='tweetButton']") with - | [] -> raise (Any (fmt "Send-tweet button not found")) - | _ as l -> - if List.length l > 1 - then raise (Any "Too many send-tweet button found") - else List.nth l 0 - in click ctx.session_id send_tweet_button; Unix.sleep 8 ;;