How to open a second tab in the same browser using Selenium Webdriver , Javascript pattern Page Object

I just can’t understand one thing. For example I have a Driver() object. Object A() and object B() are inherited from the Driver object. I use Selenium Webdriver.

class DriverObject() {

    initBrowser() {
       this.driver = new Builder().forBrowser("chrome").build();
    openPage(url) {
    openAndSwitchNewTab() {   
        this.parentWindow = this.driver.getWindowHandle();
        this.childWindow = this.driver.getWindowHandle();



class Bi() extends DriverObject{
    getTextFromElement() {}


class Ci() extends DriverObject {
    findElement() {}

let Driver = DriverObject();
let B = Bi()
let C = Ci()

I perform some actions with object B


I have already found the product. Then I want to open and switch to a new tab and also open a new site there and use the methods from the C () object. How can i do this?

I was able to do this if I inherit object C from B then I will perform all actions on the object C:


The problem is that when creating a new object to work with it, I need to initialize the driver, but then the browser opens, and if I try to open a new tab, then it happens in a new browser (that is, in two browsers are already open), I need to everything was done in one browser. The code I wrote above works. But is it right?

Source: JavaSript – Stack Overflow

November 27, 2021
Category : News
Tags: Automation | javascript | qa | selenium | webdriver

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.