Having difficulty toggling between tabs on Chrome

The Challenge:

A few months back, we implemented a test for a multiple-tab feature that involved opening tabs with CTRL/COMMAND + t and closing them with CTRL/COMMAND + v keyboard shortcuts.

Key Helper Functions:

this.getControlKey = function () {
    var isWin = /^win/.test(process.platform);
    return isWin ? protractor.Key.CONTROL : protractor.Key.COMMAND;
};

this.openAndSwitchToNewTab = function (url) {
    element(by.tagName("body")).sendKeys(protractor.Key.chord(this.getControlKey(), "t"));

    // failing, if new tab was not opened
    browser.getAllWindowHandles().then(function (handles) {
        expect(handles.length).toBeGreaterThan(1);
    });

    return browser.get(url);
};

Lately, this test has been failing with an error message stating Expected 1 to be greater than 1, indicating that the new tab was not being opened. Furthermore, both keyboard shortcuts have ceased to work.

What's causing the issue with opening and closing tabs using shortcuts?

We're currently using Protractor 2.1.0 and ChromeDriver 2.15 (also tested with the latest 2.16, with no success).


Insights and Additional Details:

  1. Initially, I suspected it might be related to Chrome 44:

    However, when testing on older Chrome versions using BrowserStack, the problem persisted.

  2. The functionality works flawlessly in Firefox.

  3. I can see the chord being sent to the body element in the logs on BrowserStack, but it doesn't trigger any action in the browser.
  4. I managed to get the code working on Windows. Therefore, the issue seems to be specific to Mac OS.
  5. I attempted various methods of sending the keys. Here are some alternatives I tried:

    browser.actions().mouseMove(element(by.tagName("body"))).sendKeys(protractor.Key.chord(this.getControlKey(), "t")).perform();
    browser.driver.switchTo().activeElement().sendKeys(protractor.Key.chord(this.getControlKey(), "t"));
    
  6. I also switched to the beta channel and encountered the same issue on Chrome 46.

  7. As a temporary solution to open a tab, I resorted to performing CTRL/COMMAND + SHIFT + click on a link within the application:

    // open new tab by clicking a logo 
    var logo = element(by.css("a.logo"));
    browser.actions().keyDown(this.getControlKey()).keyDown(protractor.Key.SHIFT).click(logo).keyUp(this.getControlKey()).keyUp(protractor.Key.SHIFT).perform();
    
    // switch to a new tab
    return browser.getAllWindowHandles().then(function (handles) {
        return browser.switchTo().window(handles[handles.length - 1]).then(function () {
            return browser.get(url);
        })
    });
    

    The challenge here is that I still can't close the tab as CTRL/COMMAND + w isn't functioning.

  8. This issue isn't limited to Protractor. Here's a snippet of Python code that opens google.com, enters "testing" in the search field, and sends COMMAND + A to select the text in the input box. While this behaves as expected in Firefox, it doesn't work in Chrome (Python 2.7, selenium 2.47.1, Chrome 46, chromedriver 2.17):

    from selenium.webdriver import ActionChains
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get('https://google.com')
    
    q = driver.find_element_by_name("q")
    q.send_keys("testing")
    
    ActionChains(driver).send_keys_to_element(q, Keys.COMMAND + "a").perform()
    

Answer №1

My testing has covered a range of Chrome versions, from 38 to 44.

It was successful on version 44 (v44.0.2403.125) when tested on Sauce Labs. I also confirmed its functionality locally on version 44.0.2403.130.

The tools used for the tests were ChromeDriver 2.17 and SeleniumWebDriver 2.47.1

I conducted these tests solely in Java, with hopes that similar results would be seen in Javascript

public static void doChromeTest(WebDriver driver) {
    for (int i = 0; i < 10; i++) {
        openTab(driver);
    }
    System.out.println("After Open Tab " + driver.getWindowHandles().size());
    for (int i = 0; i < 10; i++) {
        closeTab(driver);
    }
    System.out.println("After Close Tab " + driver.getWindowHandles().size());
    driver.quit();
}

public static void openTab(WebDriver driver) {
//Both will work
   //driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.CONTROL, "t"));
    new Actions(driver).sendKeys(Keys.chord(Keys.CONTROL, "t")).build().perform();
}

public static void closeTab(WebDriver driver) {
//Both will work
    //driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.CONTROL, "w"));
    new Actions(driver).sendKeys(Keys.chord(Keys.CONTROL, "w")).build().perform();
}

Answer №2

My understanding of the situation has greatly improved.

It seems that the issue is specific to different operating systems. After conducting tests on BrowserStack and Sauce Labs, it was evident that keyboard shortcuts with CONTROL function in Chrome 44 on Windows.

A relevant open bug report regarding Chromedriver mentioned:

The impact of this bug is more noticeable on Mac systems, as special key handling occurs in render view host view mac, which is above our simulation level. This results in certain actions like ctrl+w not closing the window on windows, and command+a selecting all on mac. Although unfortunate, these issues can mostly be worked around.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unlocking the hidden treasures: Integrating nested values into Material Table fields via column linking

I am currently working on creating a table with nested data that looks like this: [{ id: 24, name: "DANIEL TSUTOMU OBARA", number: "134", phone: "11111111111", rg: "4034092666", EmployeeStatus: { crea ...

Exploring the z-index property in CSS along with implementing mouse interaction on background using

Currently, I am attempting to incorporate a radial gradient as the background of my blog post card. My objective is for this radial gradient to move along with the cursor when the user hovers over the blog post card. To better illustrate this effect, you c ...

Looking to Extract Data from Multiple Pages with Python's Selenium Module

I am currently working on a selenium / python script that is designed to extract page titles and other details from a webpage. One challenge I am facing involves scraping multiple pages of results that are loaded via a "next" button without having to rel ...

Vue is struggling to load the component files

Lately, I've been encountering an error during webpack build that is causing some issues. ERROR There were 3 errors encountered while compiling The following relative modules could not be found: * ./components/component1.vue in ./resources/assets/ ...

Having trouble loading a chart with amcharts after sending an ajax request

I have integrated amcharts to create a pie chart. When I click a button, an AJAX request is triggered to fetch data from MySQL in JSON format. After receiving the JSON array, I pass the data to amcharts but the chart doesn't display. Oddly, if I redi ...

Exploring Angular scope variables using Jasmine while making an ajax request

Can anyone provide guidance on testing Angular scope variables in a controller that is created within an ajax request? Here's the setup: app.controller('NewQuestionCtrl', function ($scope, Question) { loadJsonAndSetScopeVariables($scope ...

Creating curved triangles in React Native is a fun and easy way to add stylish

Hello everyone, I am a newcomer to react native and I am attempting to create the following user interface. Is there any way to create a curved triangle? I have tried but I am unable to curve the edges of the triangle. https://i.stack.imgur.com/vE17U.png ...

The Jquery delete button is efficiently targeting and removing all image sources and identifiers within a Multiple Upload feature

I need help creating a delete button for my ImageUploader. I can successfully select an image and display it in a div on my page, but deleting the current image is proving to be challenging. When I click on the delete button, instead of getting the id and ...

Delay Selenium until either of the two items become visible

Is there a way to wait for one of two elements to become visible using ExpectedConditions in Selenium WebDriver? Currently, I am utilizing the ElementIsVisible method like this: WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); IWe ...

Leveraging jQuery to extract attributes from a link and send them as a form submission to a separate script

How can I extract attributes from an <a href> link and send them to another script file as post data? Here's what I have tried so far: HTML link: <a href="#" class="submit-button" id="deleteRecord" attr1="xyz" attr2="abc" >Delete</a&g ...

Please pass this as a parameter to the addEventListener() function

I'm looking to implement a change event for a set of checkboxes. How do I access this in my event function so that I can retrieve the checkbox value during the event? Below is my current code snippet: var checkboxes = document.getElementsByClassNa ...

My gaming console is malfunctioning and the controller is unresponsive

I developed an application with a login page and a controller structured like this: ----> --->over here :) (function(){ 'use strict'; angular .module("loginApp",[]) .controller("loginCtrl",loginCtrl); loginCt ...

Display a component by selecting a hyperlink in React

Currently working on a story in my storytelling, which might not be too important for the question I have. What I am trying to accomplish is creating a scenario where there is an anchor tag that, once clicked, triggers the opening of a dialog box or modal ...

Utilizing an HTML time picker for scheduling specific time intervals

Is it possible to use an HTML time picker with a specific interval? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time According to the link, the step attribute is supported, but I have tested it on the latest versions of Chrome, Edge, ...

A method for consolidating multiple enum declarations in a single TypeScript file and exporting them under a single statement to avoid direct exposure of individual enums

I am looking to consolidate multiple enums in a single file and export them under one export statement. Then, when I import this unified file in another file, I should be able to access any specific enum as needed. My current setup involves having 2 separ ...

When launching JQuery UI Tabs in a new browser tab using ajax, the HTML from the ajax response will be immediately shown

I am currently in the process of upgrading from JQuery UI 1.8.14 to JQuery UI 1.10. Previously, when using v1.8.14 code, opening a tab in a new browser tab would cause the entire page to reload, activating the default tab (tabIndex=0). However, I am faci ...

Organize items based on the values of a specific key within a JavaScript object

I have a collection of items as follows: [{ "id": "123", "title": "Article 1", "evaluationLevel": { "levelName":A }, "category": [&quo ...

Executing Selenium 2 commands to open a URL in a new tab and subsequently closing multiple tabs

Is there a way I can open a link in a new tab using Selenium 2 and then close the tab after interacting with the page? Specifically, if I have a WebElement representing an <a> tag, how can I achieve this? My setup involves utilizing the Java API of ...

Headless Selenium Browser Error: No browser instance is currently running

I've been attempting to run Edge in Headless mode, but I keep encountering the error message 'No browser is open'. Here's the Python script I'm using: from msedge.selenium_tools import EdgeOptions from msedge.selenium_tools import ...

Discovering the parent route details of the current route from within a component

I am facing an issue where I need to identify the parent route /products while working within the scope of the FeaturedProducts.vue component. The current route path for this component is set as /product-list/featured const routes = [ { path: "/ ...