V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
9yu
V2EX  ›  问与答

selenium js 怎么在 click 后等待页面 jquery 加载完成后执行动作?

  •  
  •   9yu · Feb 25, 2020 · 1577 views
    This topic created in 2262 days ago, the information mentioned may be changed or developed.

    是这样的,我在模拟登录后页面的点击,到点击"登录"按钮都是可以的,但是点击之后页面会跳转到后台页面,怎么判断页面里的 jq (例如 $(document).ready(function () {} 里绑定的 click 事件)全部加载了呢?

    官方的文档 这样加载的:

    const documentInitialised = () =>
        driver.executeScript('return initialised');
    
    await driver.get('file:///race_condition.html');
    await driver.wait(() => documentInitialised(), 10000);
    const element = driver.findElement(By.css('p'));
    assert.strictEqual(await element.getText(), 'Hello from JavaScript!');
    

    但是我按照文档的写法,会报错 driver is not defined

    1 replies    2020-02-26 02:09:16 +08:00
    ysc3839
        1
    ysc3839  
       Feb 26, 2020 via Android
    执行脚本调用 $(document).ready,在这里面通知 driver 已经加载完成。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   955 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 20:08 · PVG 04:08 · LAX 13:08 · JFK 16:08
    ♥ Do have faith in what you're doing.