webdriver.get()和webdriver.navigate.to()在包含散列和片段标识符的URL中的区别 [英] Difference between webdriver.get() and webdriver.navigate.to() in the case of urls containing hash and fragment identifier

查看:497
本文介绍了webdriver.get()和webdriver.navigate.to()在包含散列和片段标识符的URL中的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Firefox中的Selenium WebDriver时,我注意到了下面的行为:



假设您打开一个包含哈希的url: http://example.com/#app



当您尝试访问它时再次使用 webdriver.get()在Firefox中没有任何反应(当您手动选择当前的URL并按Enter键时,也会发现相同的行为)。
如果你在Chrome中这样做,页面将被重新打开。



但是当你尝试在Firefox中使用 webdriver.navigate.to()页面重新打开。



有人可以解释 webdriver.get() webdriver.navigate.to()在这种情况下?



我在这里看到 https://stackoverflow.com/a/5665218/3307322 之间没有区别这两种方法,但显然在这种情况下,他们的行为不同。



谢谢

解决方案

他们都导航到给定的网页。从答案中给出的链接可以得出结论:

lockquote

navigate()。to() get()做同样的事情。



<但是,这是你给出的一个场景,它解释了不同之处,即。 单页面应用程序



这两个方法的区别并不在于它们的行为,而在于应用程序工作方式浏览器如何处理它。

navigate()。至()通过改变网址来进入页面,就像进行前进/后退导航一样。



然而, get()刷新页面以改变URL。



因此,在应用程序域更改的情况下,这两个方法的行为相似。也就是说,页面在两种情况下都被刷新。但是,在单页面应用程序中, navigate()。()不会刷新页面, get()做。


I've noticed the following behavior while working with Selenium WebDriver in Firefox:

Given you open a url containing a hash: http://example.com/#app

When you try to access it again using webdriver.get() nothing happens in Firefox (the same behavior can be noticed when you select the current url manually and press Enter). If you do this in Chrome, the page would be re-opened.

But when you try to access the url again in Firefox using webdriver.navigate.to() the page is re-opened.

Can someone please explain the difference between webdriver.get() and webdriver.navigate.to() in this case?

I've seen here https://stackoverflow.com/a/5665218/3307322 that there's no difference between the two methods, but obviously in this case they behave differently.

Thank you.

解决方案

They both navigate to the given webpage. From the link given in the answer, it can be concluded that:

navigate().to() and get() do exactly the same thing.

But, here is a scenario that you gave which explains the difference, ie. Single-Page Applications.

The difference between these two methods comes not from their behavior, but from the behavior in the way the application works and how browser deal with it.

navigate().to() navigates to the page by changing the URL like doing forward/backward navigation.

Whereas, get() refreshes the page to changing the URL.

So, in cases where application domain changes, both the method behaves similarly. That is, page is refreshed in both the cases. But, in single-page applications, while navigate().to() do not refreshes the page, get() do.

这篇关于webdriver.get()和webdriver.navigate.to()在包含散列和片段标识符的URL中的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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