3
我們有一個表單,它有幾個單獨的提交按鈕,可以執行不同的操作。問題是我有幾個按鈕,它們具有以下HTML:機械化提交
<input type="submit" name="submit" value="Submit" class="submitLink" title="Submit" />
<input type="submit" name="submit" value="Delete" class="submitLink" title="Delete" />
現在,您不能通過標準的find_control函數按值查找元素。所以我寫了一個謂語功能,會發現我的元素,我當時希望通過以下方式點擊:
submit_button = self.br.form.find_control(predicate=submit_button_finder)
self.br.submit(submit_button)
但是都提交併單擊內部調用發現元素,並沒有方法可以讓你的加入謂詞關鍵字,所以像這樣的調用也不起作用:
self.br.submit(predicate=submit_button_finder)
有什麼我失蹤了?!?
更新:
附加了輔助函數來檢索滿足所述條件爲這樣的所有元素:
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
然後替換下面的行:
submit_button = self.br.form.find_control(predicate=submit_button_finder)
self.br.submit(submit_button)
隨着:
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()
我很確定你不應該在頁面上有兩個同名的按鈕。這可能是你的問題的一部分。 – 2010-12-21 19:52:16
@Alex我不幸的是沒有控制,但。 – Scott 2010-12-21 19:54:49