Submitting Html Form with Python's Mechanize - two submit buttons no IDs - mechanize-python

I am trying to submit a HTML button on a PHP/HTML page that contains 1 form and two different buttons that do different tasks. I need to submit the second submit button. The problem is that neither button has an id attribute and are distinguished only by their title tag.
I need to select Orders and Orderlines via a select box (which I think is correct) and press the second 'Go'/Submit button on the form.
e.g.
<form>
....
<input class="button" type="submit" value="Go">
....
then further down we have...
<select class="sfield" name="last">
<option value="0" selected="">From: First order</option>
<option value="1">From: 19/10/2012 16:22</option>
</select>
<select class="sfield" name="items">
<option value="1" selected="">Include: Orders and items</option>
<option value="0">Include: Order lines only</option>
</select>
<input class="button" type="submit" onclick="this.form.action.value='export'" title="Generate CSV file" value="Go">
My Python code snippet is as follows...
br.form['last'] = ['0'] # Select the 'From First Order'
br.form['items'] = ['1'] # Select both Orders and Order Lines
br.submit()
# When I uncomment the line below I can process a CSV file but it just contains Orders only!
# br.open("http://www.mysite.com/admin/ordermanager.php?action=export")
# Read and process CSV file from csv link displayed on repost of submitted form....
# this section below works fine.
for link in br.links(url_regex=r"export",nr=0):
resp = br.follow_link(link)
content = resp.read()
Last_Run_Date = strftime("%Y%m%d%H%M%S", localtime())
with open('c:\python27\%s.csv' % Last_Run_Date, 'w') as fo:
fo.write(content)
There does not seem to be a way of specifying the title attribute in the br.submit such as
br.submit(title='Generate CSV file') in the Mechanize documentation.
I am assuming that br.submit() is selecting the first submit control when I want the second?
Does anyone know of a clever way around this?

you could use the number of the submit button:
br.submit(nr=2)
nr starts from 0 for the first submit button

Related

How to get related value from SelectList

Using .NET 5.0 and Azure SQL
I am trying to figure out how to get a related value when I make a selection from a drop down list and pass that value to a hidden input field.
My select list (id="customer" is for the jQuery Chosen plugin):
<select id="customer" asp-for="Assignment.Retailer_ASM" class="form-control" asp-items="ViewBag.Retailer_ASM">
<option value="">--Customers--</option>
</select>
So when a user selects a customer from this list, there is a FK value that I want to pass into the hidden input, which is used for RLS.
<input type="hidden" asp-for="Assignment.RlsArea" value="What to put here?" class="form-control" />
The value would be like Assignment.Retailer_ASM.RegionID, an INT for the selected Retailer_ASM.

How Can I add currency selector on WHMCS custom page?

I am trying to add a currency selector on one of my custom pages where I have displayed the product details.
I want to allow my visitor to change the default currency from this custom page and view the product pricing accordingly.
I have added this code in my custom.tpl
<input type="hidden" name="token" value="{$LANG.go}">
<select name="currency" onchange="submit()" class="form-control">
<option value="">Change Currency (A$ AUD)</option>
{foreach from=$currencies item=listcurr}
<option value="{$listcurr.id}"{if $listcurr.id == $currency.id} selected{/if}>{$listcurr.prefix} {$listcurr.code}</option>
{/foreach}
</select>
</form> ```
But it is not working, every time I select the currency from the dropdown, it refreshes the page. but nothing changes,
please guide what I am doing wrong.
Thanks in advance
Aqsa,
You can do this. You could update your form to either:
Perform a GET request, and add the currency=$id parameter to the URL ($id being the ID for the currency in tblcurrencies.
Or
When your form submits, handle the form input, and set the currency in the session variable:
use WHMCS\Session;
Session::set('currency', $id);
Again, where $id relates to tblcurrencies.id.
Bare in mind that the currency cannot be changed for existing users, and it is not recommended changing their currency after they have made any transactions to avoid accounting/calculation issues.

How to select the correct submit button with mechanize for Python?

I'm trying to submit a form (using mechanize in Python) that has two submit buttons as shown below.
<input type="submit" value="Save Changes " name="SaveChanges">
<input type="submit" value="Reboot" name="SaveChanges">
Mechanize "print control" shows this...
<SubmitControl(SaveChanges=Save Changes )>
<SubmitControl(SaveChanges=Reboot)>
How do I select the "Reboot" submit button with mechanize? I've tried:
br.submit()
br.submit("Reboot")
br.submit("SaveChanges=Reboot")
The correct form is selected, but none of these submit options are working. I'm new to Python and would appreciate any help.
I just figured it out.
br.submit(nr=1)
will select the second submit button (nr count starts with zero)

How to assert a selected item in a dojo multiselect with selenium IDE

I've populated a multiselect using dojo and added the selected values using combo.set("value", selectedValuesArray);
Problem is that when trying to assert the selected values using selenium IDE, I can't figure out how dojo does to "select" the selected values, I would expect to be like
<option value="111" selected>name</option>
But as you can see in the image, there's no indication in the image, not in the disabled (view) or the enabled (edit) one
There's no CSS classes added either, so i don't know how to assert if the item is selected or not.
Any idea?
Here's the generated HTML
<select data-dojo-attach-event="onchange: _onChange" data-dojo-attach-point="containerNode,focusNode" name="combo_project_participants" multiple="true" class="dijitMultiSelect" tabindex="0" id="dijit_form_MultiSelect_3" widgetid="dijit_form_MultiSelect_3">
<option value="1367">name 0 AdminEdge</option>
<option value="1368">Test User name Test User lname</option>
</select>
EDIT: this didn't allowed me to upload the image...
http://imageshack.us/photo/my-images/850/cf6a.jpg
Add
data-dojo-type="dijit/form/MultiSelect"
in your select-Tag. That should fix it.
For further information look at http://dojotoolkit.org/reference-guide/1.8/dijit/form/MultiSelect.html
Regards

DOJO: How to validate (required="true") selectOneMenu

How i can validate DOJO selectOneMenu (required="true") here is some dummy code.
<select required="true" missingMessage="Ooops! You forgot your gender!"
name="gender" id="gender" data-dojo-type="dijit/form/?">
<option disabled="true" value="">Select a Gender</option>
<option value="1">Male</option>
<option value="2">Female</option>
</select>
Dojo provide 3 type of combobox :
Select
It is simple combobox like select in HTML with no validation and not provide any search facility inside select options.
ComboBox
It is pure form of combobox and name as ComboBox again it will not provide any default validation but it provide search facility within its options.
FilteringSelect
It is an advance form of select have default facility of validation and search facility. And it also has property to take value as input tag take value in HTML.
In dojo you can also try custom validation which is provided inside dojox library.
I hope it will help you.