package com.seleniumWebdriver;
import java.awt.AWTException;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 4-08-2017
*
*/
public class Arrow_Down extends SuperTestNG {
FirefoxProfile profile;
@Test(priority = 0)
public void handleArrowDown() throws InterruptedException, AWTException {
try {
driver.get("file:///D:/Office/Eclipse_Projects/Project_Neon/PracticeCode/SavedPage/Only%20Testing%20%20TextBox.htm");
WebElement oWE = driver.findElement(By.xpath("//*[text()='Tuesday, 28 January 2014']"));
System.out.println("Text: " + oWE.getText());
// right click on webpage and arrow down then press enter
Actions action = new Actions(driver);
action.contextClick(oWE).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build()
.perform();
Thread.sleep(5000);
} catch (Exception e) {
e.printStackTrace();
}
}
public void rightClick(WebElement element) {
try {
Actions action = new Actions(driver).contextClick(element);
action.build().perform();
System.out.println("Sucessfully Right clicked on the element");
} catch (StaleElementReferenceException e) {
System.out.println("Element is not attached to the page document " + e.getStackTrace());
} catch (NoSuchElementException e) {
System.out.println("Element " + element + " was not found in DOM " + e.getStackTrace());
} catch (Exception e) {
System.out.println("Element " + element + " was not clickable " + e.getStackTrace());
}
}
}
import java.awt.AWTException;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 4-08-2017
*
*/
public class Arrow_Down extends SuperTestNG {
FirefoxProfile profile;
@Test(priority = 0)
public void handleArrowDown() throws InterruptedException, AWTException {
try {
driver.get("file:///D:/Office/Eclipse_Projects/Project_Neon/PracticeCode/SavedPage/Only%20Testing%20%20TextBox.htm");
WebElement oWE = driver.findElement(By.xpath("//*[text()='Tuesday, 28 January 2014']"));
System.out.println("Text: " + oWE.getText());
// right click on webpage and arrow down then press enter
Actions action = new Actions(driver);
action.contextClick(oWE).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build()
.perform();
Thread.sleep(5000);
} catch (Exception e) {
e.printStackTrace();
}
}
public void rightClick(WebElement element) {
try {
Actions action = new Actions(driver).contextClick(element);
action.build().perform();
System.out.println("Sucessfully Right clicked on the element");
} catch (StaleElementReferenceException e) {
System.out.println("Element is not attached to the page document " + e.getStackTrace());
} catch (NoSuchElementException e) {
System.out.println("Element " + element + " was not found in DOM " + e.getStackTrace());
} catch (Exception e) {
System.out.println("Element " + element + " was not clickable " + e.getStackTrace());
}
}
}
No comments:
Post a Comment