Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open and close tabs in Chrome anymore

The Problem:

Several months ago we've added a test for a multiple-tab functionality opening tabs with CTRL/COMMAND + t and closing with CTRL/COMMAND + v keyboard shortcuts.

Relevant 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);
};

Recently, it started to fail with a Expected 1 to be greater than 1 error, which means that a new tab was not opened. And, I've confirmed that both keyboard shortcuts don't work anymore.

Why did it stop opening and closing tabs with shortcuts?

Using the currently latest Protractor 2.1.0 and ChromeDriver 2.15 (also tried with the latest 2.16, no luck).


Thoughts and more information:

  1. At first, I thought it is a Chrome 44 related problem:

    • Keys.ENTER, Keys.TAB, Keys.SPACE are not working on Chrome 44
    • Input.dispatchKeyEvents handles some keys incorrectly

    But, using BrowserStack I've reproduced the problem on older Chrome versions too.

  2. It works in Firefox like a clockwork.

  3. I can actually see the chord sent to the body element in the logs on BrowserStack, but nothing happens in the browser.
  4. I can actually make the same code work on Windows. So, it's probably Mac OS specific.
  5. I've tried to change the way the keys are sent. Here are some of my tries:

    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. Also switched to the beta channel and reproduced the same problem on Chrome 46.

  7. As a workaround, to open a tab, I can perform CTRL/COMMAND + SHIFT + click on any link inside 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 problem here is that I still cannot close the tab since CTRL/COMMAND + w does not work.

  8. It's not only Protractor specific. Here is a snippet of Python code that opens up google.com, put "testing" into the search field and sends COMMAND + A to the input box. In Firefox, it behaves as expected - selects the text in the input box, but that does not 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()
    
like image 444
alecxe Avatar asked Jul 31 '15 16:07

alecxe


People also ask

Why has Google Chrome stopped working?

Next: Troubleshoot Chrome crash problems If it works in another browser, try uninstalling and reinstalling Chrome. There could be something wrong with your Chrome profile that's causing problems. Uninstall Chrome and make sure to check the box to delete browsing data. Then, reinstall Chrome.


1 Answers

I've tested with sauclabs from chromeVersion 38 to 44

And it worked only on 44.v44.0.2403.125 to be precise on saucelabs[Tested on local[44.0.2403.130 m] as well]

And I used ChromeDriver 2.17 and SeleniumWebDriver 2.47.1

I've tried it in Java only.Hope it will be the same for 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();
}
like image 172
Madhan Avatar answered Sep 22 '22 06:09

Madhan