У меня есть скрипт, использующий pyautogui, который запускает веб-сайт из предопределенной библиотеки в зависимости от элементов имени файла. Затем он активирует другую библиотеку, чтобы выполнить набор действий для перехода по сайту и ввода данных.
Они все работают нормально, кроме «ввести адрес электронной почты». Я даже пытался записать каждый символ по отдельности и ввести time.sleep, но ничего не получалось, даже одиночное время.
Это соответствующий код:
email = "info@oakpointpartners.com"
state_actions_category_1 = {
"NV": ["5 tabs", "input CID", "tab", "input CID again", "tab", "enter email", "tab", "enter email", "tab", "enter", "wait 2 seconds", "enter filename with extension", "enter", "wait 2 seconds", "2 tabs", "1 downkey", "5 tabs", "spacebar", "tab", "enter"],
}
def perform_actions(driver, state, cid, actions, filename, is_test_file=False):
# Replace placeholders in actions with actual values
actions = [
action.replace("enter email", f"enter '{email}'")
.replace("input CID", f"input '{cid}'")
.replace("enter filename with extension", f"enter '{filename}.pdf'")
.replace("enter filename being processed", f"enter '{filename}'")
for action in actions
]
# Log actions being executed for test files
if is_test_file:
log_message(f"Executing actions for state {state}: {actions}", to_console=True)
# Open the corresponding website or mailing address
if state in state_urls:
url = state_urls[state]
driver.get(url)
time.sleep(3) # Wait for the page to load
print(f"Performing actions for state: {state}, CID: {cid} (Processing file: {filename})")
for action in actions:
if "tabs" in action:
pyautogui.press('tab', presses=int(action.split()[1]))
elif "downkey" in action:
pyautogui.press('down', presses=int(action.split()[1]))
elif "spacebar" in action:
pyautogui.press('space')
elif "enter" in action:
pyautogui.press('enter')
elif "input CID" in action:
pyautogui.write(cid)
elif "wait" in action:
time.sleep(int(action.split()[1]))
elif "enter email" in action:
# Loop through each character of the email and type it individually
for char in email:
pyautogui.write(char) # Type the individual character
time.sleep(0.1) # Add a slight delay to simulate human typing speed
pyautogui.press('tab') # Press 'tab' after typing the email
elif "enter filename being processed" in action:
# Input the filename without .pdf extension
pyautogui.write(filename)
time.sleep(0.1) # Brief delay after typing
elif "enter filename with extension" in action:
# Input the filename with .pdf extension
filename_with_extension = append_pdf_extension(filename)
pyautogui.write(filename_with_extension)
time.sleep(0.2) # 1/5 second delay after typing
Я запустил его через ChatGPT и CoPilot. Ни один из них не смог предложить решение, которое привело бы к выводу адреса электронной почты один раз. Заранее благодарим за любую информацию.
Попытался ввести time.sleep и заставить скрипт выводить отдельные символы вместо полного текста.
У меня есть скрипт, использующий pyautogui, который запускает веб-сайт из предопределенной библиотеки в зависимости от элементов имени файла. Затем он активирует другую библиотеку, чтобы выполнить набор действий для перехода по сайту и ввода данных. Они все работают нормально, кроме «ввести адрес электронной почты». Я даже пытался записать каждый символ по отдельности и ввести time.sleep, но ничего не получалось, даже одиночное время. Это соответствующий код: [code]email = "info@oakpointpartners.com"
# Replace placeholders in actions with actual values actions = [ action.replace("enter email", f"enter '{email}'") .replace("input CID", f"input '{cid}'") .replace("enter filename with extension", f"enter '{filename}.pdf'") .replace("enter filename being processed", f"enter '{filename}'") for action in actions ]
# Log actions being executed for test files if is_test_file: log_message(f"Executing actions for state {state}: {actions}", to_console=True)
# Open the corresponding website or mailing address if state in state_urls: url = state_urls[state] driver.get(url) time.sleep(3) # Wait for the page to load print(f"Performing actions for state: {state}, CID: {cid} (Processing file: {filename})")
for action in actions: if "tabs" in action: pyautogui.press('tab', presses=int(action.split()[1])) elif "downkey" in action: pyautogui.press('down', presses=int(action.split()[1])) elif "spacebar" in action: pyautogui.press('space') elif "enter" in action: pyautogui.press('enter') elif "input CID" in action: pyautogui.write(cid) elif "wait" in action: time.sleep(int(action.split()[1])) elif "enter email" in action: # Loop through each character of the email and type it individually for char in email: pyautogui.write(char) # Type the individual character time.sleep(0.1) # Add a slight delay to simulate human typing speed pyautogui.press('tab') # Press 'tab' after typing the email elif "enter filename being processed" in action: # Input the filename without .pdf extension pyautogui.write(filename) time.sleep(0.1) # Brief delay after typing elif "enter filename with extension" in action: # Input the filename with .pdf extension filename_with_extension = append_pdf_extension(filename) pyautogui.write(filename_with_extension) time.sleep(0.2) # 1/5 second delay after typing [/code] Я запустил его через ChatGPT и CoPilot. Ни один из них не смог предложить решение, которое привело бы к выводу адреса электронной почты один раз. Заранее благодарим за любую информацию. Попытался ввести time.sleep и заставить скрипт выводить отдельные символы вместо полного текста.