![]() The switchTo method is also how you handle alerts, so the steps will be very similar. This allows you to change control from one tab to another. followed by sendKeys(Keys.CONTROL+”t”) You can probably already tell that we’re focusing on our webpage, then sending ctrl + t to open a new tab the way you might normally in your browser.Īny time you switch between tabs, you’ll want to use the driver.switchTo().window() method. To first open a new tab (if one doesn’t open automatically when clicking a link), you’ll use driver.findElement(By.cssSelector(“body”)). With multi-tab testing, you might want to: How do we handle this in our automated tests? The good news is that it’s not as hard as it seems. For instance, any anchor tag with an attribute like target=”_blank” will open the link in a new tab. Multi-tab testing is a common annoyance for testers who are learning Selenium - how do you open more than one tab in a single browser window, then switch back and forth between them? Many pages do this on their own. Just like you might open web pages in different tabs locally, it’s also possible to have multiple tabs up in one browser during a Selenium test. ![]() Luckily, once you know the right commands, you can begin creating scripts that reach all parts of the application you need to check. As we’ve discovered through this Selenium 101 Series, automation can be challenging when your tests require more complex actions such as testing in two windows at once or closing a pop-up.
0 Comments
Leave a Reply. |