1

Trying to enter the value "100000" into a web form using Selenium in Python, but it is consistently not working no matter how I try to send it.

I apologize for my lack of knowledge about the terminology. I will try my best but I am self-taught and a novice. Also, I apologize but I cannot tell you the website or my employer would not be very happy.

The box on the webpage is automatically populated with a dollar sign. I know that the box in the web form is expecting an integer in currency format. When I look at the html element on the web page it gives the following information

<input type="number" step="1" name="moneying" size="35" id="moneying" 
class="moneying input currency error" value="" data-type="currency" data- 
mandopt="mand" required="" pattern="[\$]?[0-9]+[\.]?[0-9]*" min="500" 
onblur="validate(this);">

I have tried:

  • using the send_keys class just plain without any variation
  • clicking the box before using send_keys
  • clearing the box before using send_keys
  • waiting until the element can be located on the page and then doing all the above
  • using send_keys with Keys.NUMPAD#
  • adding $ in the beginning of the number
  • adding \$ in the beginning of the number
  • using Firefox driver instead of Chrome driver
  • entering the value as 100000.00 and 100000

Current version of my code:

    from selenium import webdriver
    driver = webdriver.Chrome('location on my pc')
    try:
        driver.get(r"relevant web page")
        moneying_box_wait = WebDriverWait(driver,20).until(EC.presence_of_element_located((By.ID,"moneying")))
        moneying_box = driver.find_element_by_id("moneying")
        moneying_box.click()
        moneying_box.clear()
        moneying_box.send_keys("100000")

I want it to enter 100000 in the box. Nothing appears in the box at all.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • If you remove the `try`, what error do you see? (if any) What if you send a number instead of a string? `send_keys(100000)` Beyond those 2 things, it's basically impossible to know what the problem might be without seeing the page. In general, make sure Selenium is doing all the actions (and waits) you would do if you did this yourself manually. That sounds obvious but it's often the problem. – Mike B Jan 10 '19 at 02:40
  • Thanks for the suggestion. Send_keys didn't do anything differently if I enter as a number instead of a string. The "try" is because this is only one segment of a much larger section of code. The rest of the code is working it's just this one part that isn't. – Esther C.R.B. Jan 10 '19 at 18:02

1 Answers1

2

As you intend to send a character sequence instead of presence_of_element_located you need to use element_to_be_clickable and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.moneying.input.currency.error#moneying"))).send_keys("$1000.0")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='moneying input currency error' and @id='moneying']"))).send_keys("$1000.0")
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352