简体   繁体   English

Selenium 等待直到加载新页面,JavaScript

[英]Selenium Wait Until New Page Is Loaded, JavaScript

I need to wait until the webpage is loaded after clicking a link.我需要等到点击链接后加载网页。 The new page's title is not changed, only the url changed from "something.com" to "something.com/abc".新页面的标题没有改变,只是url从“something.com”变成了“something.com/abc”。 So I can't use所以我不能用

 driver.wait(until.titleIs('new title'));.

Is there any function I can use?有什么我可以使用的功能吗?

There are the relevant built-in urlIs and urlContains expected conditions:有相关的内置urlIsurlContains预期条件:

driver.wait(until.urlIs('url'));
driver.wait(until.urlContains('partOfUrl'));

You can try binding the event to the element that appears.您可以尝试将事件绑定到出现的元素。

const getElementById = async (id, timeout = 2000) => {
   const el = await driver.wait(until.elementLocated(By.id(id)), timeout);
   return await driver.wait(until.elementIsVisible(el), timeout);
};

someElement = await getElementById("someId");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM