webdriver.get() 和 webdriver.navigate() 的区别 [英] Difference between webdriver.get() and webdriver.navigate()

查看:21
本文介绍了webdriver.get() 和 webdriver.navigate() 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

get()navigate() 方法有什么区别?是否有任何方法或其他方法等待页面内容加载?我真正需要的是像 Selenium 1.0 的 WaitForPageToLoad 之类的东西,但要通过 webdriver 使用.

What is the difference between get() and navigate() methods? Does any of this or maybe another method waits for page content to load? What do I really need is something like Selenium 1.0's WaitForPageToLoad but for using via webdriver.

有什么建议吗?

推荐答案

导航

您想要使用 WebDriver 做的第一件事是导航到一个页面.执行此操作的正常方法是调用 get:

driver.get("http://www.google.com");

WebDriver 将等待页面完全加载(即 onload 事件已触发),然后再将控制权返回给您的测试或脚本.值得注意的是,如果您的页面在加载时使用了大量 AJAX,那么 WebDriver 可能不知道它何时完全加载.如果您需要确保此类页面完全加载,则可以使用 waits.

WebDriver will wait until the page has fully loaded (that is, the onload event has fired) before returning control to your test or script. It’s worth noting that if your page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded then you can use waits.

之前,我们介绍了如何使用 get 命令 (driver.get("http://www.example.com")) 导航到页面已经看到,WebDriver 有许多较小的、以任务为中心的界面,导航是一项有用的任务.由于加载页面是一项基本要求,因此执行此操作的方法存在于主 WebDriver 接口中,但它只是以下内容的同义词:

Earlier, we covered navigating to a page using the get command (driver.get("http://www.example.com")) As you’ve seen, WebDriver has a number of smaller, task-focused interfaces, and navigation is a useful task. Because loading a page is such a fundamental requirement, the method to do this lives on the main WebDriver interface, but it’s simply a synonym to:

driver.navigate().to("http://www.example.com");

重申:navigate().to()get() 做的完全一样.一个比另一个更容易打字!

To reiterate: navigate().to() and get() do exactly the same thing. One's just a lot easier to type than the other!

navigate 界面还提供了在浏览器历史记录中前后移动的功能:

The navigate interface also exposes the ability to move backwards and forwards in your browser’s history:

driver.navigate().forward();
driver.navigate().back();

(强调)

这篇关于webdriver.get() 和 webdriver.navigate() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆