Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how can i press a key using action class i java ?

package automationFramework;

import static org.junit.Assert.assertEquals;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class KeyboardEvents {

	public static void main(String[] args) {
		
        // Initialize ChromeDriver
	// Here we assume that the ChromeDriver path has been set in the System Global variables
        WebDriver driver=new ChromeDriver();
       
        //Navigate to the demo site
        driver.get("https://demoqa.com/text-box");
       
        // Enter the Full Name
        WebElement fullName = driver.findElement(By.id("userName"));
        fullName.sendKeys("Mr.Peter Haynes");
        
        //Enter the Email
        WebElement email=driver.findElement(By.id("userEmail"));
        email.sendKeys("PeterHaynes@toolsqa.com");
        
        // Enter the Current Address
        WebElement currentAddress=driver.findElement(By.id("currentAddress"));
        currentAddress.sendKeys("43 School Lane London EC71 9GO");
        
        // Copy the Current Address
        currentAddress.sendKeys(Keys.CONTROL);
        currentAddress.sendKeys("A");
        currentAddress.sendKeys(Keys.CONTROL);
        currentAddress.sendKeys("C");
        
        //Press the TAB Key to Switch Focus to Permanent Address
        currentAddress.sendKeys(Keys.TAB);
        
        //Paste the Address in the Permanent Address field
        WebElement permanentAddress=driver.findElement(By.id("permanentAddress"));
        permanentAddress.sendKeys(Keys.CONTROL);
        permanentAddress.sendKeys("V");
        
        //Compare Text of current Address and Permanent Address
        assertEquals(currentAddress.getAttribute("value"),permanentAddress.getAttribute("value"));
        
        driver.close();

	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: is overriding only works with inherited methods? 
Java :: android autocompletetextview hashmap 
Java :: how to reorder numbers in a list randomly in java 
Java :: what isz meaning of EL in jsp 
Java :: how to pass string between activities android 
Java :: how to create an abstract class in java 
Java :: checkboslisttilw in flutter 
Java :: binomial heap implementation java 
Java :: java non blocking notifier 
Java :: javax big int validation in spring boot 
Java :: move the zero elementts in array in java in tutorialspoint.dev 
Java :: java domande risposta multipla 
Java :: open external hostservices url in javafx 
Java :: get material of block bukkit 
Java :: jaggies 
Java :: h2-gramer-conf 
Java :: Java array with objects from different types 
Java :: LayerRenderer 
Java :: newinstance in java giving exception 
Java :: quick way to get charAt 
Java :: how to compare two characters in java 
Java :: method in java 
Java :: java join array 
Java :: how to get stack trace of a function in java 
Java :: java union type 
Java :: error: incompatible types: NonExistentClass cannot be converted to Annotation 
Java :: get sum of int array and return string 
Java :: como limpar a tela do consola no java 
Sql :: search text in all sql server stored procedure 
Sql :: mysql get table size 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =