Click Javascript link href

0

I'm doing a code to enter a platform. It has a URL which I access and log in through Mechanize.

import mechanize

br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent','Chrome')]
#URL del Login
br.open('https://platform.ttt/en/login')
br.select_form(nr=0)
#Info del Login, Buscar forms desde la pagina y donde dice 'username' ponemos el name cuando inspeccionamos en el browser!
br.form['username'] = 'martin@ttt'
br.form['password'] = 'martinttt'
#Logueate
sub = br.submit()
#Url logueado
print sub.geturl()
#Cambio de URL
br.open('https://ttt/en/users/inventory/43a05221-5760-4eba-a40d-087856e79fbb/general')
print br.geturl()

With this code, just log in and change url. Within the new URL I need to click on: <a id="clone-btn" href="javascript:void(0);">Duplicate</a>

I thought about clicking on the href but I can not then maybe I can select it through the ID. To be more clear, I need to be able to click clone-btn

Thanks

    
asked by Martin Bouhier 29.09.2017 в 18:52
source

1 answer

0

This is an idea of how you could do it in another way - using javascript.

Inside the URL = new page, change the <a></a> for an input.

Example:

<input type="button" id="myBtn" onclick="clickAEsteBoton();">Este es un botón</input>

Then on that same page where you have the button, you would place this function:

function clickAEsteBoton() {
    // Coloca aquí tu código javascript que desees ejecutar.
    // Si quieres abrir una nueva ventana, usa por ejemplo:
    window.open('https://es.stackoverflow.com');
}

To call this function, invoke the function in document.ready , like this:

$(document).ready(function() {
    clickAEsteBoton();
});
    
answered by 29.09.2017 в 21:54