课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Tabs

Tabs

- [Instructor] Clicking a link may open a new tab or window. Let's look at how Selenium Web driver allows us to navigate between multiple open web pages. After clicking the button, which opens a new window to get all of the open windows, we'll say var windows = driver.getWindowHandles(). This gives us a set of unique identifiers that represent each browser window or tab that is currently open within this session. In fact, let's print these out. So these handles allow you to switch control between the different tabs or windows that are open, but don't worry, you don't need to know these exact identifiers. Web driver provides convenience methods. For example, if we want to move the focus to the new tab we just opened, we can say driver.switchTo().window(), and we can provide the handle for the window, which we can get from our Windows collection. However, be careful because getWindowHandles() returns a set and this data structure does not guarantee order. So we cannot assume that the…

内容