Python mechannize 'NoneType object has no attribute 'click()' with br.submit(name=s)

StackOverflow https://stackoverflow.com/questions/22109471

  •  18-10-2022
  •  | 
  •  

Вопрос

what i'm trying to do is automate my browsing tasks using python mechanize there are four buttons with different names in the html form. I've selected the form using command br.select_form(nr=0). Now

s='NameofButton1'
br.submit(name=s)

is working good. But as i have to click on all the four buttons so i.m using for loop and the code goes like this

sBegin='NameofButton'
l=['1','2','3','4']
for item in l:
    s=sBegin+item
    br.submit(name=s)

is not working and giving error 'NoneType' object has no attribute 'click'.

Это было полезно?

Решение

after you submit the fist button, your browser state will be redirected to result page.

so i suggest before you begin to submit your form, you should reopen the initial page where you can find those buttons

sBegin='NameofButton'
l=['1','2','3','4']
for item in l:
    s=sBegin+item
    br.open("url to initial page")
    br.submit(name=s)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top