[Python] Is it possible to create/simulate a custom pagination element to jump to a specific...

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am using python and selenium to look through a table with a lot of pages. I was wondering if it is possible to jump to a specific page of that table to continue searching through it where i left off previously. My problem is that i have no knowledge about JavaScript or jQuery. The pagination looks like this:

    <nav id="stat_pagination_nav">
    <ul id="stat_pagination" class="pagination pagination-sm noselect">
    <li class="first disabled"><a href="#">&lt;&lt;</a></li>
    <li class="prev disabled"><a href="#">&lt;</a></li>
    <li class="page active"><a href="#">1</a></li>
    <li class="page"><a href="#">2</a></li>
    <li class="page"><a href="#">3</a></li>
    <li class="page"><a href="#">4</a></li>
    <li class="page"><a href="#">5</a></li>
    <li class="page"><a href="#">6</a></li>
    <li class="page"><a href="#">7</a></li>
    <li class="next"><a href="#">&gt;</a></li>
    </ul>
    </nav>


    Inspecting these elements in the browser shows an event on click that looks like this:

    function(x) {
    !g.options.href && x.preventDefault(), g.show(parseInt(m.data("page")))
    }


    Using the debugger also in the browser it seems its a part of this:

    setupEvents: function () {
    var g = this;
    this.$listContainer.find('li').each(
    function () {
    var m = c(this);
    if (
    m.off(),
    m.hasClass(g.options.disabledClass) ||
    m.hasClass(g.options.activeClass)
    ) {
    m.on('click', !1);
    return
    }
    m.click(
    function (x) {
    !g.options.href &&
    x.preventDefault(),
    g.show(parseInt(m.data('page')))
    }
    )
    }
    )
    },


    which is a part of a massive .js file.

    It looks to me like this: g.show(parseInt(m.data("page"))) is the interesting part, where we jump to the page. But i find it really hard to understand this code using only single letters for names so i am probably missing something. However this led to my attempt:

    myPage = 42
    js = "arguments[0].g.show(" + str(myPage) + ");"
    selector = "#stat_pagination > li:nth-child(7)"
    element = WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.CSS_SELECTOR, selector)))
    driver.execute_script(js, element)


    i tried this using different selectors, thinking i might be in the wrong scope where g does not exist but everything yielded the same error. JavascriptException: TypeError: can't access property "show", arguments[0].g is undefined

    After some google research i also tried using js = "var keys = Object.keys(arguments[0]); return keys;" to understand the problem better and it returned a list containing a single string: "jQuery111306146748258537055" Im obviously missing something essential here but i dont know what it is. This is my first question here, please let me know if i need to include more information.

    Continue reading...

Compartilhe esta Página