Nityesh Agarwal
Nityesh Agarwal

Reputation: 504

How to choose submit button name using element id in MechanicalSoup?

I need to simulate the submit action on a form that has 2 options for submit button with both the options having the same name attribute. Here's how they look using the Inspect tool:

enter image description here

So, they differ in their id and value attributes but not the name attribute.

The problem I am having is that the submit_selected() method in MechanicalSoup only accepts Button Name as the parameter:

submit_selected(btnName=None, *args, **kwargs)

So how can I use this method to uniquely select the appropriate button?

Upvotes: 0

Views: 1340

Answers (2)

Alex
Alex

Reputation: 187

If I'm not mistaken, you can use other attributes. For instance, we can use id or value from your example as they are not identical. like so....

by id

my_button = br.get_current_page().find('input', id='edit-save')

br.submit_selected(btnName=my_button)

by value

my_button = br.get_current_page().find('input', value='Search')

br.submit_selected(btnName=my_button)

Upvotes: 0

Matthieu Moy
Matthieu Moy

Reputation: 16647

Use Form.choose_submit. This function can receive a BeautifulSoup Tag element, so you can use whatever BeautifulSoup provides to select the right submit button.

Upvotes: 0

Related Questions