Python Forum

Full Version: Click on button with python mechanize
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I would like to click a button using mechanize but I can't find the right code.

Until then, I had succeeded because I was going through the mobile version of twitter and I didn't have to deal with javascript.

Apparently for this page it is not possible. I would like to avoid using selenium, is it possible to do a
br.submit()
on the blue button below?

[Image: zWNGswn.png]

Thank you !
try this
br.submit(id='allow')
if there is javascript in there, then you cannot do it with mechanize. You will need selenium.
Thank you very much for your answer.

I got this error:

Quote:Traceback (most recent call last):
File "test.Acc0unt_Cr3at0r.2.py", line 165, in <module>
br.submit(id='allow')
File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 541, in submit
return self.open(self.click(*args, **kwds))
File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 530, in click
request = self.form.click(*args, **kwds)
AttributeError: 'NoneType' object has no attribute 'click'
A couple ways to test if javascript is the issue.

1) turn javascript off on your browser and see if the button is selectable or even viewable. If not then javascript is providing it. I dont have a twitter account so i cannot test it.

2) See if BeautifulSoup can see the button. If it cannot then most likely it is javascript.

I would check that first. If javascript is the problem, then your are shit out of luck and must use selenium.