Python Automation for Manual Data Entry – Can’t Identify Fields

I get accounting data from one software. I extract rows with errors. I create new rows (so they alternate) with the correct data. Then I go into a different software & manually type all this crap back out. Should be easy to automate.

I successfully wrote a Python script to log into the web app, contingency for needing to wait for a MFA. It navigates to the data entry page successfully, but then fails to identify any of the data entry fields; timing out & spitting back the same errors. I’ve added some “debugging” & even had a source.html file created to help troubleshoot. This is the script I’m using

Python Script:

`import time
import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from selenium.common.exceptions import TimeoutException, NoSuchElementException, ElementNotInteractableException

# Initialize Chrome WebDriver using WebDriver Manager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

# Navigate to the login page
driver.get('starting url')

# Locate the input fields and enter credentials
cruzid_field = driver.find_element(By.NAME, 'j_username')
password_field = driver.find_element(By.NAME, 'j_password')

# Enter your credentials
cruzid_field.send_keys('actual username')
password_field.send_keys('actual password')

# Click the login button
login_button = driver.find_element(By.NAME, '_eventId_proceed')
login_button.click()

# After successful login, locate the search input field and enter the search term
try:
    WebDriverWait(driver, 60).until(EC.url_contains('next url'))
    print("Logged in successfully!")

    # Locate the search input field using its ID
    search_field = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.ID, 'search-landing'))
    )
    search_field.send_keys('data entry code')

    # Simulate pressing Enter to initiate the search
    search_field.send_keys(Keys.RETURN)

    # Switch to the iframe containing the content
    print("Switching to iframe")
    iframe = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located((By.ID, 'bannerHS'))
    )
    driver.switch_to.frame(iframe)
    print("Switched to iframe")

    # Verify the current context is the iframe
    current_frame = driver.execute_script("return self.name")
    print(f"Current iframe context: {current_frame}")

    # Wait for the tab-container element to be present after search (up to 120 seconds)
    print("Waiting for the tab-container element to be present")
    tab_container = WebDriverWait(driver, 120).until(
        EC.presence_of_element_located((By.ID, 'tab-container'))
    )
    print("Tab-container element is present, search completed!")

    # Attempt to locate the "Go" button using ID
    print("Attempting to locate the Go button by ID")
    go_button = WebDriverWait(driver, 20).until(
        EC.element_to_be_clickable((By.ID, 'frames6'))
    )
    go_button.click()
    print("Go button clicked successfully!")

    # Wait for the pnlFgbjvch1Canvas element to appear
    print("Waiting for pnlFgbjvch1Canvas element to be present")
    pnl_element = WebDriverWait(driver, 60).until(
        EC.presence_of_element_located((By.ID, 'pnlFgbjvch1Canvas'))
    )
    print("pnlFgbjvch1Canvas element is present")

    # Adding a brief delay to ensure the element is ready for interaction
    time.sleep(2)

    ***# Pause for manual date and document total entry*** PROBLEM 1
    input("Please enter the transaction date and document total manually, then press Enter to continue...")

    *# Wait for the specific div elements to be present* PROBLEM 2
    print("Waiting for the view div element to be present")
    view_div = WebDriverWait(driver, 60).until(
        EC.presence_of_element_located((By.ID, 'view_16d82cc3-d839-4611-aaf5-6c06ddf7b162'))
    )
    print("View div element is present")

    print("Waiting for the collapsible panel (rect145) to be present")
    collapsible_panel = WebDriverWait(driver, 60).until(
        EC.presence_of_element_located((By.ID, 'rect145'))
    )
    print("Collapsible panel (rect145) is present")

    # Perform the tab action to move to the next field
    print("Performing tab action")
    body = driver.find_element(By.TAG_NAME, 'body')
    body.send_keys(Keys.TAB)

    print("Waiting for the frames29 panel to be present")
    frames_panel = WebDriverWait(driver, 60).until(
        EC.presence_of_element_located((By.ID, 'frames29'))
    )
    print("Frames29 panel is present")

    # Click the input field with ID inp:fgbjvcdRuclCode
    print("Locating the RUCL Code input field")
    rucl_code_input = WebDriverWait(driver, 20).until(
        EC.element_to_be_clickable((By.ID, 'inp:fgbjvcdRuclCode'))
    )
    rucl_code_input.click()
    print("RUCL Code input field clicked")

    # Read the 4-character code from the Excel file
    print("Reading the 4-character code from the Excel file")
    df = pd.read_excel('file/path')
    code = df.iloc[0, 0]
    print(f"Code read from Excel: {code}")

    # Enter the code into the input field
    print("Entering the code into the RUCL Code input field")
    rucl_code_input.send_keys(code)

    print("Complete")
    time.sleep(30)

except (TimeoutException, NoSuchElementException, ElementNotInteractableException) as e:
    print(f"Error occurred: {e}")

# Close the browser
driver.quit()`


I replaced Problem 1 with the following to use XPATH to identify the field. The first time I ran it, it succeeded & tabbed to the next field. The second time I ran it; it failed:

`
# Use a more robust XPath to locate the transaction date input field
    print("Locating the transaction date input field")
    transaction_date_input = WebDriverWait(driver, 20).until(
        EC.presence_of_element_located(
            (By.XPATH, '//input[contains(@id, "fgbjvchTransDate") and @name="fgbjvchTransDate"]'))
    )
    print("Transaction date input field located")

    # Ensure the element is visible and interactable
    WebDriverWait(driver, 20).until(
        EC.visibility_of(transaction_date_input)
    )
    WebDriverWait(driver, 20).until(
        EC.element_to_be_clickable(transaction_date_input)
    )

    # Click into the transaction date input field
    print("Clicking the transaction date input field")
    transaction_date_input.click()

    # Perform the tab action
    print("Performing tab action")
    transaction_date_input.send_keys(Keys.TAB)
`

New contributor

hi.jrdn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật