Open a new tab in the browser using Selenium WebDriver in java

Tram Ho

Want to open a new tab in the same browser that is running? Instead of opening a new browser, you can use the methods below to open a new tab in the same browser

Method 1. This way I often use

After you have opened a new tab, you have to switch to a new tab to work on that new tab

Method 2. Using javascripts

Want to open to any path, you just need to replace the above link with a corresponding link. But this will have problems when running with IE – IE it will show a line asking you if you want to open another tab or not, so it will not be convenient if you use this way with IE.

Method 3. Using Action class

Method 4: Use the Robot class to open

As we’ve all heard of Robot class in Selenium, it’s easy to understand that robots are used to simulate events related to keyboard operations, or mouse clicks, so it should be with the field. In this case, we can imagine doing it by hand and simulating our code will do the same thanks to the robot. First press Control + t to open a new tab, after the new tab is opened, we will move the mouse focus on this new tab and open a new link in that tab only.

Reference source: https://artoftesting.com/open-a-new-tab-in-selenium-webdriver-java

https://www.testingexcellence.com/open-new-tab-browser-using-selenium-webdriver-java/

Share the news now

Source : Viblo