Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
3812 Prikazi

Hi, everyone.

First of all, I hope you are very well.

I created a method which loads an URL where there is a form, and to get the results from this form, I have to set a captcha code from a captcha image.

That captcha image only updates if the URL loads again in the browser.

I'm using selenium to set the values needed for the inputs automatically, but before doing that, I take a screenshot to the website and I cropped that image to extract only the captcha image portion and save it in a directory called 'static'.

So, I put the captcha image inside an action window, doing this executing the method from a button.

My question is.. How can I update the image automatically when I click the button? What can I add in my code to do it?

Regards.

My code:

Python

@api.multi
def load_webpage(self):
"""
Load the SENIAT url and download the captcha image
"""
global driver

driver = webdriver.PhantomJS(service_log_path='/opt/odoo10/apps/ghostdriver.log') # Open a browser session
driver.get('http://contribuyente.seniat.gob.ve/BuscaRif/BuscaRif.jsp')

driver.save_screenshot("/opt/odoo10/apps/hr_nomina/static/src/img/seniat_page.png") # Taking the screenshot
img = Image.open("/opt/odoo10/apps/hr_nomina/static/src/img/seniat_page.png")
captcha_img = img.crop((41, 200, 162, 230)) # Croping the captcha portion from image
captcha_img.save("/opt/odoo10/apps/hr_nomina/static/src/img/captcha.png")


View

<record id="captcha_view" model="ir.ui.view">
<field name="name">captcha.view</field>
<field name="model">captcha.window</field>
<field name="arch" type="xml">
<form>
<group name="group_top">
<group name="group_left">
<field name="captcha_code"/>
<button name="load_webpage" string="Cargar Captcha" type="object" class="oe_highlight"/>
</group>
<group name="group_right">
<img src="/hr_nomina/static/src/img/captcha.png" id="captcha_img"/>
</group>
</group>
<footer>
<button name="main" string="Actualizar" type="object" class="oe_highlight"/>
</footer>
</form>
</field>
</record>



Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
jul. 25
2801
1
maj 20
3882
0
mar. 20
3919
1
maj 19
5237
1
feb. 16
4772