代码之家  ›  专栏  ›  技术社区  ›  LLScheme

无法使用Playwright&Pyppeteer找到关键字

  •  1
  • LLScheme  · 技术社区  · 6 月前

    因此,在使用各种Python自动化工具(如Playwright和Pyppeteer)时,我似乎无法抓住“继续使用谷歌”按钮 https://dropbox.com/login 。当我通过控制台这样做时:

    const element = [...document.querySelectorAll('span,button,div,a')].find(el => el.textContent.includes('Doorgaan met Google'));
    
    // Check if the element is found and click it
    if (element) {
        element.click();
        console.log('Button clicked successfully!');
    } else {
        console.error('Button not found!');
    }
    

    它在Chrome中找到并点击了按钮,但在Firefox中没有。在我用Playwright和Pyppeteer编写的程序中,我也找不到按钮(尽管有时只是评估相同的JS代码)。

    有人知道这是怎么回事吗?

    提前感谢。

    1 回复  |  直到 6 月前
        1
  •  1
  •   Lajos Arpad    6 月前

    显然,为FireFox生成的结构与为其他浏览器生成的结构不同。这对我在FireFox上奏效了:

    document.querySelector(".L5Fo6c-bF1uUb").click()
    

    在FireFox中,按钮具有以下结构:

    <div id="some_id_here" class="L5Fo6c-bF1uUb" tabindex="0"></div>
    

    没有内部文本。这就是为什么你的脚本在FireFox中找不到它的原因。