no text entered on webpage but vs code log I coded says all the texts have been input

54 views Asked by At

I coded an automatic booking program for tennis courts with Selenium in Python.

It is supposed to work the way as below :

  1. The program goes to the booking website, signs in and directly moves to the page for the booking form.
  2. It repeats accessing the page until the booking opens at a specific time.
  3. once the page shows up, the program fills out the form by entering entry boxes and clicking the submit button.

Problem. No input boxes in the form is not shown entered, even though elem.get_attribute('value') prints the values of those on the terminal. No exception errors occurred. Plus, some time after the booking form is open(not right after but like after 10 seconds), it works properly when I rerun the code.

What seems to be the cause?

I really appreciate all your help in advance!

I tried running the code several times on the booking day, only to fail to book each time.

P.S. part of my code is below :

# <main code>
BOOKING_ADDR = 'https://sports.gangseo.seoul.kr/fmcs/28'


Bot_bang = Tennis_booking(CHROME_DRIVER_ADDR)

Bot_bang.goto_booking_site(BOOKING_ADDR)
Bot_bang.login('230128', '123456!')

Bot_bang.goto_booking_directly(Bot_bang.first_hwang_direct_booking_path)
Bot_bang.booking_finish()

Bot_bang.goto_booking_directly(Bot_bang.second_hwang_direct_booking_path)
Bot_bang.booking_finish()



# <booking_finish()>
def booking_finish(self, run = 1) :
        if run == 1 :
            # enter num of players
            self.input_validation('users', '4')

            # enter purpose of using the court
            self.input_validation('purpose', 'a')

            # click agree checkbox to rules and regulations
            self.input_validation('agree_use1', True, 'checkbox')

            # Click submit button
            elems = self.driver.find_elements(By.CLASS_NAME, 'button.action_write')
            self.driver.execute_script("arguments[0].click();", elems[1])



# <input_validation()>
def input_validation(self, id, value, input_mode='free') :

        # input field type : text box
        if input_mode == 'free' :
            # input
            elem = WebDriverWait(self.driver, 1200).until(EC.presence_of_element_located((By.ID, id)))
            self.driver.execute_script(f"arguments[0].value ='{value}'", elem)
            
            # validation
            if elem.get_attribute('value') == str(value):
                print(f'input {value} is the same as output {elem.get_attribute("value")}.')
                pass
            else :
                return self.input_validation(id, value, input_mode)
       

        # input field type : checkbox
        elif input_mode == 'checkbox' :
            # Click the box
            elem = WebDriverWait(self.driver, 1200).until(EC.presence_of_element_located((By.ID, id)))
            self.driver.execute_script("arguments[0].click();", elem)

            # validation
            if elem.is_selected() == value :
                pass
            else :
                return self.input_validation(id, value, input_mode)
0

There are 0 answers