Java Code Examples for org.openqa.selenium.Keys#chord()

The following examples show how to use org.openqa.selenium.Keys#chord() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
/**
 * Simulates pressing a key (or a combination of keys).
 * (Unfortunately not all combinations seem to be accepted by all drivers, e.g.
 * Chrome on OSX seems to ignore Command+A or Command+T; https://code.google.com/p/selenium/issues/detail?id=5919).
 * @param key key to press, can be a normal letter (e.g. 'M') or a special key (e.g. 'down').
 *            Combinations can be passed by separating the keys to send with '+' (e.g. Command + T).
 * @return true, if an element was active the key could be sent to.
 */
public boolean press(String key) {
    CharSequence s;
    String[] parts = key.split("\\s*\\+\\s*");
    if (parts.length > 1
            && !"".equals(parts[0]) && !"".equals(parts[1])) {
        CharSequence[] sequence = new CharSequence[parts.length];
        for (int i = 0; i < parts.length; i++) {
            sequence[i] = parseKey(parts[i]);
        }
        s = Keys.chord(sequence);
    } else {
        s = parseKey(key);
    }

    return sendKeysToActiveElement(s);
}
 
Example 2
Source File: RoundUpSteps.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Эмулирует нажатие сочетания клавиш на клавиатуре.
 * Допустим, чтобы эмулировать нажатие на Ctrl+A, в таблице должны быть следующие значения
 * | CONTROL |
 * | a       |
 *
 * @param keyNames название клавиши
 */
@И("^выполнено нажатие на сочетание клавиш из таблицы$")
@And("^pressed keyboard shortcut from the table$")
public void pressKeyCombination(List<String> keyNames) {
    Iterable<CharSequence> listKeys = keyNames.stream()
            .map(this::getKeyOrCharacter)
            .collect(Collectors.toList());
    String combination = Keys.chord(listKeys);
    switchTo().activeElement().sendKeys(combination);
}
 
Example 3
Source File: KeyPressGesture.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean _executeGesture( WebDriver webDriver )
{
	String[] keyCodes = getKeyCode().split("\\+");
	String keyPressed = null;
	List<CharSequence> charSequence = new ArrayList<CharSequence>();
	
	for (String keyCode : keyCodes) {
		
		try
		{
			charSequence.add(Keys.valueOf(keyCode.toUpperCase()));
		}
		catch( Exception e )
		{
			charSequence.add( keyCode );
		}
		
	}
	
	if (charSequence.size() > 0) {
		Iterable<CharSequence> iterable = charSequence;
		keyPressed = Keys.chord(iterable);
		
		if ( webElement != null )
			new Actions( webDriver ).sendKeys(keyPressed).perform();
		else
			new Actions( webDriver ).sendKeys(keyPressed).perform();
		
		
		//new Actions( webDriver ).moveToElement( webElement ).keyDown( Keys.CONTROL ).sendKeys( "A" ).keyUp( Keys.CONTROL ).perform();
	}
	return true;
}
 
Example 4
Source File: TheiaTerminal.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void copyTerminalTextToClipboard(int terminalIndex) {
  Dimension textLayerSize = getTextLayer(terminalIndex).getSize();
  final Actions action = seleniumWebDriverHelper.getAction();

  final int xBeginCoordinateShift = -(textLayerSize.getWidth() / 2);
  final int yBeginCoordinateShift = -(textLayerSize.getHeight() / 2);

  seleniumWebDriverHelper.moveCursorTo(getTextLayer(terminalIndex));

  // shift to top left corner
  seleniumWebDriverHelper
      .getAction()
      .moveByOffset(xBeginCoordinateShift, yBeginCoordinateShift)
      .perform();

  // select all terminal area by mouse
  action.clickAndHold().perform();
  seleniumWebDriverHelper
      .getAction()
      .moveByOffset(textLayerSize.getWidth(), textLayerSize.getHeight())
      .perform();

  action.release().perform();

  // copy terminal output to clipboard
  String keysCombination = Keys.chord(CONTROL, INSERT);
  seleniumWebDriverHelper.sendKeys(keysCombination);

  // cancel terminal area selection
  clickOnTerminal(terminalIndex);
}
 
Example 5
Source File: OpenApplicationAction.java    From xframium-java with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean _executeAction( WebDriver webDriver, List<Object> parameterList )
{
	String executionId = getExecutionId( webDriver );
	String deviceName = getDeviceName( webDriver );
	
	String applicationName = (String) parameterList.get( 0 );

	ApplicationDescriptor appDesc = ApplicationRegistry.instance( ( (DeviceWebDriver) webDriver).getxFID() ).getApplication( applicationName );
	
	if ( appDesc == null )
	    throw new ScriptConfigurationException( "The Application " + applicationName + " does not exist" );

	
	if ( appDesc.isWeb() )
	{
   		String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
   		if ( webDriver.getWindowHandles() != null && webDriver.getWindowHandles().size() > 0 )
   		    webDriver.findElement(By.tagName("body")).sendKeys(selectLinkOpeninNewTab);
   		
   		webDriver.get( appDesc.getUrl() );
   		( (DeviceWebDriver) webDriver ).setAut( appDesc,  ( (DeviceWebDriver) webDriver ).getxFID()  );
   		    
	}
	else
	{
   		Handset localDevice = PerfectoMobile.instance( ( (DeviceWebDriver) webDriver ).getxFID() ).devices().getDevice( deviceName );
   		Execution appExec = null;
   		if ( localDevice.getOs().toLowerCase().equals( "ios" ) )				
   			appExec = PerfectoMobile.instance( ( (DeviceWebDriver) webDriver ).getxFID() ).application().open( executionId, deviceName, appDesc.getName(), appDesc.getAppleIdentifier() );
   		else if ( localDevice.getOs().toLowerCase().equals( "android" ) )
   			appExec = PerfectoMobile.instance( ( (DeviceWebDriver) webDriver ).getxFID() ).application().open( executionId, deviceName, appDesc.getName(), appDesc.getAndroidIdentifier() );
   		else
   			throw new IllegalArgumentException( "Could not install application to " + localDevice.getOs() );
   		
   		if ( appExec != null )
   		{
   		    if ( appExec.getStatus().toLowerCase().equals( "success" ) )
   		    {
   		        if ( webDriver instanceof ContextAware )
   	                ( ( ContextAware ) webDriver ).context( "NATIVE_APP" );
   		        
   		        ( (DeviceWebDriver) webDriver ).setAut( appDesc,  ( (DeviceWebDriver) webDriver ).getxFID()  );
   		        return true;
   		    }
   		    else
   		        throw new ScriptException( "Failed to launch application " + appDesc.getName() );
   		}
   		else 
   		    throw new ScriptException( "Failed to launch application " + appDesc.getName() );
   		
   		
	}
	return true;
}
 
Example 6
Source File: TheiaEditor.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
public void performPasteAction() {
  String keysCombination = Keys.chord(Keys.CONTROL, "v");
  seleniumWebDriverHelper.sendKeys(keysCombination);
}
 
Example 7
Source File: Utils.java    From supbot with MIT License 3 votes vote down vote up
public static String ConvertNumberToTag(String text, String regex){


        Matcher matcher = Pattern.compile(regex).matcher(text);

        String toConcatBefore = "@";
        String toConcatAfter = Keys.chord(Keys.UP,Keys.ENTER);


        int count = 0;
        while(matcher.find()) {

            int offset = count*(toConcatAfter.length()+toConcatAfter.length());

            text = text.substring(0, matcher.start() + offset)
                    +toConcatBefore
                    +text.substring(matcher.start() + offset);

            text = text.substring(0, matcher.end() + offset + toConcatBefore.length())
                    + toConcatAfter
                    + text.substring(matcher.end() + offset + toConcatBefore.length());

            count++;

        }

        return text;

    }