How to do copy Paste in browser using selenium using Actions class
Its possible to copy the text from webelement and then paste it in another webelement.
org.openqa.selenium.interactions.Actions class is used to simulate keyboard actions.
We will use three methods from selenium Actions class
1. keyDown(CharSequence key) - This method returns Actions object and performs a modifier key press, does not release the modifier key so that subsequent interactions may assume it's kept pressed.
2. sendKeys(CharSequence... keys) - This method also returns Actions class object and sends keys to the active element.
3. keyUp(CharSequence key) - This method also returns Actions class object and performs a modifier key release.
Please find below the code for implementing this.
WebElement urlTextField = driver.findElement(By.cssSelector("input[id=\"urlinput\"]");
urlTextField.sendKeys("abc123");
Actions builder = new Actions(driver);
builder.keyDown( Keys.CONTROL ).sendKeys( "a" ).keyUp( Keys.CONTROL ).build().perform();
builder.keyDown( Keys.CONTROL ).sendKeys( "c" ).keyUp( Keys.CONTROL ).build().perform();
WebElement descPaste = driver.findElement(By.cssSelector("input[id=\"descriptioninput\"]");
descPaste.click();
builder.keyDown( Keys.CONTROL ).sendKeys( "v" ).keyUp( Keys.CONTROL ).build().perform();
***************************************************************************************
QACult Best Software Testing Courses in Chandigarh tricity.- We love to enhance your knowledge.
QACult is the premier institute catering to the requirements of experienced and fresh pass-out that gives leaders like you a new way to experience Quality engineering—while you work and giving you the flexibility to both advance your career.
Our faculty have 12+ years of industrial experience and have developed many automation testing frameworks in java using TestNG or BDD (cucumber) methodology. We expertise in developing automation testing frameworks in java, python, javascript, php, ruby(WATIR-webdriver & Capybara) and Appium.
please subscribe our channel for more such updates:
Our faculty have 12+ years of industrial experience and have developed many automation testing frameworks in java using TestNG or BDD (cucumber) methodology. We expertise in developing automation testing frameworks in java, python, javascript, php, ruby(WATIR-webdriver & Capybara) and Appium.
please subscribe our channel for more such updates:
And visit for website: www.qacult.com for various blogs and Upcoming Events.
Comments
Post a Comment