Python Forum
I have created a bot in python but getting issue in element selection
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have created a bot in python but getting issue in element selection
#1
Hi guys I have created a python but for registering WordPress accounts for me on their register URLs but after registering I got an email I have give instructions to the bot

Instructions

1) Wait 2 sec for page to settle.
2) Wait 3 sec before modifying the password field.
3) Clear the existing password (CTRL+A, Backspace).
4) Paste the default password.
5) Press Enter 'enter_click_amount' times.
6) Wait for the success text "Your password has been reset. Log in".
7) If troubleshot_mode is off, wait post_enter_delay seconds, close the window, then wait an additional post_enter_delay seconds.
Otherwise, leave the window open.
8) Return True if successful; else False.

But the issue is the bot is not pressing enter even i am not touching my keyboard but still it is not pressing enter button which is important to save new password

I have tried detecting HTML element but due to different languages it is to hard to detect

Here is the code of that main function can someone please help me??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
###############################################################################
#  HANDLE THE RESET PASS FORM WITH NEW DELAYS, MULTIPLE ENTER CLICKS, & TOGGLE  #
###############################################################################
import time
 
 
def handle_reset_pass_form(page, username, update_status_func, append_results_func, default_password,
                           enter_click_amount, post_enter_delay, troubleshot_mode) -> bool:
    """
    1) Wait 2 sec for page to settle.
    2) Wait 3 sec before modifying the password field.
    3) Clear the existing password (CTRL+A, Backspace).
    4) Paste the default password.
    5) Press Enter 'enter_click_amount' times.
    6) Wait for the success text "Your password has been reset. Log in".
    7) If troubleshot_mode is off, wait post_enter_delay seconds, close the window, then wait an additional post_enter_delay seconds.
       Otherwise, leave the window open.
    8) Return True if successful; else False.
    """
    update_status_func("Waiting 2 seconds for password field to settle...")
    time.sleep(2)
 
    update_status_func("Checking for reset password form...")
    try:
        page.wait_for_selector("form#resetpassform", timeout=10000)
    except TimeoutError:
        update_status_func("Reset password form not found in time.")
        return False
 
    pass1_selector = 'input#pass1'
    try:
        page.wait_for_selector(pass1_selector, timeout=5000)
    except TimeoutError:
        update_status_func("Pass1 field not found. Cannot proceed with reset.")
        return False
 
    try:
        data_pw = page.get_attribute(pass1_selector, "data-pw")
        if data_pw and data_pw.strip():
            current_pw = data_pw.strip()
            update_status_func(f"Current password from data-pw: {current_pw}")
        else:
            current_pw = page.input_value(pass1_selector)
            update_status_func(f"Current password from pass1: {current_pw}")
    except Exception as e:
        update_status_func(f"Error reading pass1 or data-pw: {str(e)}")
        current_pw = ""
 
    update_status_func("Waiting 3 seconds before modifying the password field...")
    time.sleep(3)
 
    try:
        page.wait_for_selector(pass1_selector, timeout=5000)
        page.locator(pass1_selector).click()
        page.keyboard.press("Control+A")
        page.keyboard.press("Backspace")
        page.fill(pass1_selector, default_password)
        update_status_func("Default password pasted into the input field.")
    except TimeoutError:
        update_status_func("Pass1 field not found for clearing/pasting default password (timeout).")
        return False
 
    save_btn_selector = 'input#wp-submit.button.button-primary.button-large[value="Save Password"]'
    update_status_func("Pressing Enter on 'Save Password' for reset form...")
    try:
        page.wait_for_selector(save_btn_selector, timeout=5000)
        save_btn_locator = page.locator(save_btn_selector)
        save_btn_locator.focus()
        for _ in range(enter_click_amount):
            page.keyboard.press("Enter")
        update_status_func("Pressed Enter(s) on 'Save Password'.")
        update_status_func("Waiting for success text (15s)...")
        try:
            page.wait_for_selector('text=Your password has been reset. Log in', timeout=15000)
            update_status_func("Success: 'Your password has been reset. Log in' found.")
            update_status_func(f"Waiting {post_enter_delay} seconds after success...")
            time.sleep(post_enter_delay)
            if not troubleshot_mode:
                page.close()
                update_status_func(f"Window closed. Waiting additional {post_enter_delay} seconds...")
                time.sleep(post_enter_delay)
            else:
                update_status_func("Troubleshot mode enabled; window remains open.")
            return True
        except TimeoutError:
            update_status_func("Timeout waiting for success text. Window remains open.")
            return False
    except TimeoutError:
        update_status_func("Could not find 'Save Password' by selector (timeout). Window remains open.")
        return False
    except Exception as e:
        update_status_func(f"Error pressing Enter on 'Save Password': {str(e)}. Window remains open.")
        return False
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find all “*.wav” files that created yesterday on linux host with python. pydeev 6 6,444 Jan-07-2020, 06:43 AM
Last Post: pydeev
  Unable to locate element no such element gahhon 6 5,619 Feb-18-2019, 02:09 PM
Last Post: gahhon
  Selection based of variables issue nikos 14 7,779 Feb-09-2019, 08:23 AM
Last Post: nikos
  Opening txt file created in python in excel fabipc 1 3,186 Aug-05-2018, 11:59 PM
Last Post: ichabod801
  Can this type of project be created with Python ? AbdallahBeraidaPro 7 5,281 Jan-07-2018, 03:50 PM
Last Post: AbdallahBeraidaPro
  Change single element in 2D list changes every 1D element AceScottie 9 14,105 Nov-13-2017, 07:05 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020