Olivia
Olivia

Reputation: 1

How to debug MechanicalSoup form submission?

I am testing a form on a website using MechanicalSoup. The form has a few different radio inputs and I want to iterate through each of the inputs and check that the form opens the correct page. I can't post the exact code with the website for business/privacy reasons, but this is my generic process.

When I select the input for the radio button with name='dummyVar' and check if it worked using brwsr.launch_browser(), I can see that brwsr has selected the correct input. However, when I submit the form, the brwsr.launch_browser() always opens the page connected to the first radio input option, even when I can see that the 2nd, 3rd, etc. input button has just been selected. The website works when I am navigating through the form in a regular browser, but I am curious why the MechanicalSoup StatefulBrowser I created does not properly open the pages linked to each radio input.

brwsr = mechanicalsoup.StatefulBrowser(
            soup_config={'features': 'lxml'},  
            raise_on_404=True,
            user_agent='MyBot/0.1: ' + url,
                )

brwsr.open(url)
e_form = brwsr.select_form(nr=0)

e_form['dummyVar'] = child['value'] #selecting applicable radio input (THIS WORKS PROPERLY)
brwsr.launch_browser() #this confirms that the form is selecting the correct radio input

brwsr.submit_selected() #submit engine form
brwsr.launch_browser() #checking if correct page is opened (WHERE PROBLEM OCCURS: only ever opens page attached to first radio input button)

Any help or advice would be greatly appreciated!! Thanks!

Upvotes: 0

Views: 191

Answers (0)

Related Questions