【问题标题】:Selenium WebDriver go to page without waiting for page loadSelenium WebDriver 无需等待页面加载即可转到页面
【发布时间】:2012-07-12 09:39:39
【问题描述】:

我正在使用 python api 将一些 Selenium RC 测试转换为 Selenium WebDriver。在 Selenium WebDriver 中,我注意到 driver.get( 'http://...' ) 似乎要等待整个页面加载后再继续。有没有办法不等待页面加载?我请求的一些页面有很多外部资源,可能需要很长时间才能加载。我宁愿等待 DOM 上的元素出现,也不愿等待所有内容加载。因此,我在 WebDriver 中的一些测试似乎花费了两倍的时间。

【问题讨论】:

  • @Slanec 你们俩都很棒。我的艰苦探索终于有了一个圆满的结局。

标签: selenium webdriver


【解决方案1】:

是和不是。从 Selenium 2.24.1 开始,the support for this is only in Firefox - you have to run it in a special "mode":

FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("webdriver.load.strategy", "unstable");
WebDriver driver = new FirefoxDriver(fp);

您甚至可以设置the timeout if you want to。此方法在 Firefox 以外的任何浏览器中都失败,并且在没有不稳定策略的情况下在 Firefox 中什么也不做:

driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-07-07
  • 1970-01-01
  • 2018-08-13
  • 2019-01-31
  • 1970-01-01
  • 1970-01-01
  • 2018-03-20
  • 2017-03-27
相关资源
最近更新 更多