Dispatch mechanisms

We have a form that has several separate submit buttons that perform different actions. The problem is that I have several buttons that have the following HTML:

<input type="submit" name="submit" value="Submit" class="submitLink" title="Submit" />
<input type="submit" name="submit" value="Delete" class="submitLink" title="Delete" />

Now you cannot find an element by value with the standard find_control function. So I wrote a predicate function that will find my element, which I then hoped to click as follows:

submit_button = self.br.form.find_control(predicate=submit_button_finder)
self.br.submit(submit_button)

However, both send and click the search element of the internal call, and none of the methods allows you to add a predicate keyword, so this call does not work:

self.br.submit(predicate=submit_button_finder)

Is there anything that I am missing?!?

Update:

An auxiliary function has been added to retrieve all elements matching the criteria:

def find_controls(self, name=None, type=None, kind=None, id=None, predicate=None, label=None):

  i = 0
  results = []

  try :
    while(True):
      results.append(self.browswer.find_control(name, type, kind, id, predicate, label, nr=i))
      i += 1
  except Exception as e: #Exception tossed if control not found
    pass
  return results

Then replaced the following lines:

submit_button = self.br.form.find_control(predicate=submit_button_finder)
self.br.submit(submit_button)

WITH

submit_button = self.br.form.find_control(predicate=submit_button_finder)
submit_buttons = self.find_controls(type="submit")
for button in submit_buttons[:]:
  if (button != submit_button) : self.br.form.controls.remove(button)
self.br.submit()
+3
1

- , , , . :

for each in form.controls[:]:
  if each not "some criteria":
    form.controls.remove(each)

- , SubmitControl. , , browser.submit() , .

+3

Source: https://habr.com/ru/post/1781516/


All Articles