Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created May 8, 2020 14:50
Show Gist options
  • Save muditlambda/65c30943005132b7499e31e5c142dd36 to your computer and use it in GitHub Desktop.
Save muditlambda/65c30943005132b7499e31e5c142dd36 to your computer and use it in GitHub Desktop.
// include all the required modules from selenium web driver and Protractor framework for Protractor tutorial //
import { browser, element, by, ElementFinder, ProtractorBrowser, Protractor} from 'Protractor'
// describing the test for the mouse action demonstration for Selenium test automation//
describe(' Keyboard Action Demonstration in Protractor ', function() {
// disable synchronization for non angular websites //
browser.ignoreSynchronization = true;
browser.manage().window().maximize()
// the test case which defines how to handle keyboard actions in Protractor //
it(' Tests to handle keyboard actions in Protractor ', function() {
// this is required to wait and assign implicit time value to 15 seconds
browser.manage().timeouts().implicitlyWait(15000);
browser.get(" http://the-internet.herokuapp.com/key_presses ")
browser.actions()
.click(element(by.name("E")))
.keyDown(Protractor.Key.SHIFT)
.sendKeys("p")
.keyUp(Protractor.Key.SHIFT)
.perform()
});
});
@divyat-git
Copy link

Hi,

Below is my code related to multiple selection using keyboard shortcut. But it is not working for me in chrome browser.
Can you pls suggest me on this?

   var elem1 = browser.driver.findElement(by.xpath('//*[@id="Spreadsheet_main_content"]/div[1]/table/tbody/tr[2]/td[6]'));
    var elem2 = browser.driver.findElement(by.xpath('//*[@id="Spreadsheet_main_content"]/div[1]/table/tbody/tr[5]/td[6]'));
    browser.actions().click(elem1).keyDown(protractor.Key.SHIFT).perform();
    browser.driver.sleep(500);
    browser.actions().click(elem2).keyUp(protractor.Key.SHIFT).perform();
    browser.driver.sleep(500);

Regards,
Divya T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment