There are number of actions that can be performed on web element using Selenium Web Driver.
Most of the actions to performed on elements are common. So instead of writing repetitive steps to perform those actions we can create a class having all methods and call them wherever we needed them. We just need to pass two parameters in the method.
ElementLocator: To identify element on which action to be performed
Data: To pass values to element or to pass expected result
While calling navigate method pass URL in data parameter
If response code of URL is not 200 then it will throw an exception.
public static void navigate(String ElementLocator, String data){
try{
driver.get(data);
URL url = new URL(data);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
int statusCode = http.getResponseCode();
if(statusCode==200)
{
Log.info("Navigating to URL");
DriverScript.Message = "Navigating to URL " + data;
Thread.sleep(3000);
DriverScript.bResult=true;
}
else
{
throw new Exception();
}
}catch(Exception e){
Log.info("Not able to navigate --- " + e.getMessage());
DriverScript.bResult = false;
DriverScript.Message = "Not able to navigate --- " + e.getMessage();
}
}
public static void navigateBack(String ElementLocator, String data){
try{
Log.info("Navigating back");
Thread.sleep(2000);
driver.navigate().back();
DriverScript.Message = "Navigating back ";
Thread.sleep(2000);
DriverScript.bResult=true;
}catch(Exception e){
Log.info("Not able to navigate back--- " + e.getMessage());
DriverScript.bResult = false;
DriverScript.Message = "Not able to navigate back--- " + e.getMessage();
}
}
public static void refresh(String ElementLocator, String data){
try{
Log.info("Refreshing current page");
Thread.sleep(2000);
driver.navigate().refresh();
DriverScript.Message = "Refreshing current page";
Thread.sleep(2000);
DriverScript.bResult=true;
}catch(Exception e){
Log.info("Not able to refresh page--- " + e.getMessage());
DriverScript.bResult = false;
DriverScript.Message = "Not able to refresh page--- " + e.getMessage();
}
}
public static void clickByClass(String ElementLocator, String data){
try{
Log.info("Clicking on Web element "+ ElementLocator);
driver.findElement(By.className(ElementLocator)).click();
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clickbyXpath(String ElementLocator, String data){
try{
Log.info("Clicking on Web element "+ ElementLocator);
driver.findElement(By.xpath(ElementLocator)).click();
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void ClickByJSXpath(String ElementLocator, String data){
try{
Log.info("Click on Web element"+ElementLocator);
Thread.sleep(2000);
WebElement element = driver.findElement(By.xpath(ElementLocator));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
DriverScript.Message = "Click on Web element"+ElementLocator;
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clickByCSSSelector(String ElementLocator, String data){
try{
Log.info("Clicking on Web element "+ ElementLocator);
driver.findElement(By.cssSelector(ElementLocator)).click();
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clickByPartiallink(String ElementLocator, String data){
try{
Log.info("Clicking on Webelement "+ ElementLocator);
driver.findElement(By.partialLinkText(ElementLocator)).click();
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
clickByText: Clicking element by Label of element. Here we will pass Label in data parameter.In the ElementLocator parameter we will pass tag name in which element is located for e.g. //a,//button,//input,etc.In the data parameter we will pass the Label of the element
public static void clickByText(String ElementLocator, String data){
try{
Log.info("Clicking on Webelement "+ ElementLocator);
driver.findElement(By.xpath(ElementLocator+"[contains(.,'"+data+"')]")).click();
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clickByTextLast(String ElementLocator, String data){
try{
Log.info("Clicking on Webelement "+ ElementLocator);
driver.findElement(By.xpath(("("+ElementLocator+"[contains(.,'"+data+"')])")+"[last()]")).click();
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clickByTextJS(String ElementLocator, String data){
try{
Log.info("Clicking on Webelement "+ ElementLocator);
WebElement element = driver.findElement(By.xpath(("("+ElementLocator+"[contains(.,'"+data+"')])")));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clickByTextJSLast(String ElementLocator, String data){
try{
Log.info("Clicking on Webelement "+ ElementLocator);
WebElement element = driver.findElement(By.xpath(("("+ElementLocator+"[contains(.,'"+data+"')])")+"[last()]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clickMoveMouse(String ElementLocator, String data){
try{
Log.info("Moving over element"+ElementLocator);
Thread.sleep(2000);
WebElement searchBtn = driver.findElement(By.xpath(ElementLocator));
Actions action = new Actions(driver);
action.moveToElement(searchBtn).click().perform();
DriverScript.Message = "Moving over element"+ElementLocator;
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to move mouse --- " + e.getMessage());
DriverScript.Message = "Not able to move mouse --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void submit(String ElementLocator, String data){
try{
Log.info("Clicking on Web element "+ ElementLocator);
driver.findElement(By.xpath(ElementLocator)).submit();
DriverScript.Message = "Clicking on Web element "+ ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to click --- " + e.getMessage());
DriverScript.Message = "Not able to click --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void pressEnter(String ElementLocator, String data){
try{
Log.info("Pressing enter key on keyboard " + ElementLocator);
try {
Robot robot = new Robot();
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(500);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
Thread.sleep(3000);
DriverScript.bResult = true;
DriverScript.Message = "Pressing enter key on keyboard " + ElementLocator;
}catch(Exception e){
Log.error("Not able to press enter key--- " + e.getMessage());
DriverScript.Message = "Not able to press enter key--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void AlertAccept(String ElementLocator, String data){
try{
Log.info("Accepting Alert"+ElementLocator);
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
DriverScript.Message = "Alert Accepted --- ";
DriverScript.bResult = true;
}catch(Exception e){
Log.error("Not able to accept alert --- " + e.getMessage());
DriverScript.Message = "Not able to accept alert --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void AlertDismiss(String ElementLocator, String data){
try{
Log.info("Dismissing alert"+ElementLocator);
Alert alert = driver.switchTo().alert();
alert.dismiss();
DriverScript.Message = "Alert Dismissed --- ";
DriverScript.bResult = true;
}catch(Exception e){
Log.error("Not able to dismiss alert --- " + e.getMessage());
DriverScript.Message = "Not able to dismiss alert --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void input(String ElementLocator, String data){
try{
Log.info("Entering the text in " + ElementLocator);
driver.findElement(By.xpath(ElementLocator)).sendKeys(data);
DriverScript.Message = "Entering the text " +data +" in the " + ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to Enter UserName --- " + e.getMessage());
DriverScript.Message = "Not able to Enter UserName --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void inputByCSS(String ElementLocator, String data){
try{
Log.info("Entering the text in " + ElementLocator);
driver.findElement(By.cssSelector(ElementLocator)).sendKeys(data);
DriverScript.Message = "Entering the text in " +data +" in the " + ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to Enter UserName --- " + e.getMessage());
DriverScript.Message = "Not able to Enter UserName --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clear(String ElementLocator, String data){
try{
Log.info("Clearing text in " + ElementLocator);
driver.findElement(By.xpath(ElementLocator)).clear();
DriverScript.Message = "Clearing text in " + ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to clear text --- " + e.getMessage());
DriverScript.Message = "Not able to clear text --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void clearByCSS(String ElementLocator, String data){
try{
Log.info("Clearing text in " + ElementLocator);
driver.findElement(By.cssSelector(ElementLocator)).clear();
DriverScript.Message = "Clearing text in " + ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to clear text --- " + e.getMessage());
DriverScript.Message = "Not able to clear text --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void SelectDDByValue(String ElementLocator, String data){
try{
Thread.sleep(2000);
Log.info("Selecting drop down from the " + ElementLocator);
Select selectByValue = new Select(driver.findElement(By.xpath(ElementLocator)));
selectByValue.selectByValue(data);
DriverScript.Message = "Selecting drop down value "+data+ " from the " + ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to select DD value --- " + e.getMessage());
DriverScript.Message = "Not able to select DD value --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void SelectDDByValueCSS(String ElementLocator, String data){
try{
Thread.sleep(2000);
Log.info("Selecting drop down from the " + ElementLocator);
Select selectByValue = new Select(driver.findElement(By.cssSelector(ElementLocator)));
selectByValue.selectByValue(data);
DriverScript.Message = "Selecting drop down from the "+data+ " from the " + ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to select DD value --- " + e.getMessage());
DriverScript.Message = "Not able to select DD value --- " + e.getMessage();
DriverScript.bResult = false;
}
}
Selecting Drop Down by using Value.
Pass Visible Text in data paramter.
public static void SelectDDByVisibleText(String ElementLocator, String data){
try{
Thread.sleep(2000);
Log.info("Selecting drop down from the " + ElementLocator);
Select selectByValue = new Select(driver.findElement(By.xpath(ElementLocator)));
selectByValue.selectByVisibleText(data);
DriverScript.Message = "Selecting drop down value "+data+ " from the " + ElementLocator;
Thread.sleep(3000);
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to select DD value --- " + e.getMessage());
DriverScript.Message = "Not able to select DD value --- " + e.getMessage();
DriverScript.bResult = false;
}
}
Pass wait interval as parameter in data field
public static void wait(String ElementLocator, String data) throws Exception{
try{
Log.info("Wait for 5 seconds");
Thread.sleep(data);
DriverScript.Message = "Wait for 5 seconds";
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to Wait --- " + e.getMessage());
DriverScript.Message = "Not able to Wait --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void closeBrowser(String ElementLocator, String data){
try{
Log.info("Closing the browser");
driver.quit();
DriverScript.Message = "Closing the browser";
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to Close the Browser --- " + e.getMessage());
DriverScript.Message = "Not able to Close the Browser --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void MoveMouse(String ElementLocator, String data){
try{
Log.info("Moving over element"+ElementLocator);
WebElement el= driver.findElement(By.xpath(ElementLocator));
Actions action = new Actions(driver);
action.moveToElement(el).perform();
DriverScript.Message = "Moving over element"+ElementLocator;
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to move mouse --- " + e.getMessage());
DriverScript.Message = "Not able to move mouse --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyTextPresentByTagName(String ElementLocator, String data){
try{
Log.info("Verifying text is present " + ElementLocator);
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName(ElementLocator)));
String bodyText = el.getText();
String bodyText_lower = bodyText.toLowerCase();
String data_lower = data.toLowerCase();
if(bodyText_lower.contains(data_lower))
{
DriverScript.bResult = true;
}
else
{
throw new Exception();
}
DriverScript.Message = "Verifying text "+data+ " is present for " + ElementLocator;
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify Text by TagName--- " + e.getMessage());
DriverScript.Message = "Not able to Verify Text by TagName--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyTextPresentByXpath(String ElementLocator, String data){
try{
Log.info("Verifying text is present " + ElementLocator);
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(ElementLocator)));
String bodyText = el.getText();
String bodyText_lower = bodyText.toLowerCase();
String data_lower = data.toLowerCase();
if(bodyText_lower.contains(data_lower))
{
DriverScript.bResult = true;
DriverScript.Message = "Verifying text "+data+ " is present for " + ElementLocator;
}
else
{
throw new Exception();
}
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify Text --- " + e.getMessage());
DriverScript.Message = "Not able to Verify Text --- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyTextPresentByClassName(String ElementLocator, String data){
try{
Log.info("Verifying text is present for " + ElementLocator);
String bodyText = driver.findElement(By.className(ElementLocator)).getText();
String bodyText_lower = bodyText.toLowerCase();
String data_lower = data.toLowerCase();
if(bodyText_lower.contains(data_lower))
{
DriverScript.bResult = true;
DriverScript.Message = "Verifying text "+data+ " is present for " + ElementLocator;
}
else
{
throw new Exception();
}
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify Text by ClassName--- " + e.getMessage());
DriverScript.Message = "Not able to Verify Text by ClassName--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyTextPresentByCSS(String ElementLocator, String data){
try{
Log.info("Verifying text is present for " + ElementLocator);
String bodyText = driver.findElement(By.cssSelector(ElementLocator)).getText();
String bodyText_lower = bodyText.toLowerCase();
String data_lower = data.toLowerCase();
if(bodyText_lower.contains(data_lower))
{
DriverScript.bResult = true;
DriverScript.Message = "Verifying text "+data+ " is present for " + ElementLocator;
}
else
{
throw new Exception();
}
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify Text by ClassName--- " + e.getMessage());
DriverScript.Message = "Not able to Verify Text by ClassName--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyByURL(String ElementLocator, String data){
try{
Log.info("Verifying URL for " + ElementLocator);
String URL = driver.getCurrentUrl();
String URL_lower = URL.toLowerCase();
String data_lower = data.toLowerCase();
if(URL_lower.contains(data_lower))
{
DriverScript.bResult = true;
DriverScript.Message = "Verifying URL "+data+ " is present for " + ElementLocator;
}
else
{
throw new Exception();
}
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify by URL--- " + e.getMessage());
DriverScript.Message = "Not able to Verify by URL--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyByImage(String ElementLocator, String data){
try{
Log.info("Verifying Image is displayed for " + ElementLocator);
WebElement element = driver.findElement(By.xpath(ElementLocator));
String src = ((JavascriptExecutor)driver).executeScript("return arguments[0].attributes['src'].value;", element).toString();
String src_lower = src.toLowerCase();
String data_lower = data.toLowerCase();
if(src_lower.contains(data_lower))
{
DriverScript.bResult = true;
DriverScript.Message = "Verifying Image "+data+ " is present for " + ElementLocator;
}
else
{
throw new Exception();
}
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify Image by Xpath--- " + e.getMessage());
DriverScript.Message = "Not able to Verify Image by Xpath--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyByImageCSS(String ElementLocator, String data){
try{
Log.info("Verifying Image is displayed for " + ElementLocator);
WebElement element = driver.findElement(By.cssSelector(ElementLocator));
String src = ((JavascriptExecutor)driver).executeScript("return arguments[0].attributes['src'].value;", element).toString();
String src_lower = src.toLowerCase();
String data_lower = data.toLowerCase();
if(src_lower.contains(data_lower))
{
DriverScript.bResult = true;
DriverScript.Message = "Verifying Image "+data+ " is present for " + ElementLocator;
}
else
{
throw new Exception();
}
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify Image by CSS--- " + e.getMessage());
DriverScript.Message = "Not able to Verify Image by CSS--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void VerifyFileDownloaded(String ElementLocator, String data){
try{
File dir = new File("downloadpath");
System.out.println("downloadpath");
System.out.println(data);
File[] files = dir.listFiles();
if (files == null || files.length == 0) {
DriverScript.bResult = false;
DriverScript.Message = "Not able to Verify file download--- ";
}
for (int i = 1; i < files.length; i++) {
if(files[i].getName().contains(data)) {
DriverScript.bResult = true;
DriverScript.Message = "Uploaded Image " + data;
}
}
Thread.sleep(3000);
}catch(Exception e){
Log.error("Not able to Verify file download--- " + e.getMessage());
DriverScript.Message = "Not able to Verify file download--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void UploadImage(String ElementLocator, String data){
try{
Log.info("Uploading Image for " + ElementLocator);
StringSelection stringSelection_filepath = new StringSelection(data);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection_filepath, null);
Thread.sleep(500);
System.out.println("File path"+data);
try {
Robot robot = new Robot();
// Press CTRL+V
robot.setAutoDelay(100);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
//Release CTRL+V
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.setAutoDelay(100);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
Thread.sleep(3000);
DriverScript.bResult = true;
DriverScript.Message = "Uploaded Image " + data;
}catch(Exception e){
Log.error("Not able to upload image--- " + e.getMessage());
DriverScript.Message = "Not able to upload image--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void ScrollUp(String ElementLocator, String data){
try{
Log.info("Scrolling Up " + ElementLocator);
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,-250)", "");
jse.executeScript("window.scrollBy(0,-250)", "");
/*
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_PAGE_UP);
robot.keyPress(KeyEvent.VK_PAGE_UP);
robot.keyPress(KeyEvent.VK_PAGE_UP);
*/
Thread.sleep(3000);
DriverScript.bResult = true;
DriverScript.Message = "Scroll Up " + ElementLocator;
}catch(Exception e){
Log.error("Not able to Scroll up--- " + e.getMessage());
DriverScript.Message = "Not able to Scroll up--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void ScrollDown(String ElementLocator, String data){
try{
Log.info("Scrolling Down " + ElementLocator);
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");
jse.executeScript("window.scrollBy(0,250)", "");
/*
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
*/
Thread.sleep(3000);
DriverScript.bResult = true;
DriverScript.Message = "Scroll Down " + ElementLocator;
}catch(Exception e){
Log.error("Not able to Scroll Down--- " + e.getMessage());
DriverScript.Message = "Not able to Scroll Down--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void DragAndDrop(String ElementLocator, String data){
try{
WebElement elementToMove = driver.findElement(By.xpath(ElementLocator));
WebElement moveToElement = driver.findElement(By.xpath(data));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(elementToMove).moveToElement(moveToElement).release(moveToElement).build();
dragAndDrop.perform();
Thread.sleep(3000);
DriverScript.bResult = true;
DriverScript.Message = "Drag and Drop " + ElementLocator;
}catch(Exception e){
Log.error("Not able to Drag and Drop--- " + e.getMessage());
DriverScript.Message = "Not able to Drag and Drop--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void Slide(String ElementLocator, String data){
try{
WebElement dragElementFrom = driver.findElement(By.xpath(ElementLocator));
new Actions(driver).dragAndDropBy(dragElementFrom, data, 0).build().perform();
Thread.sleep(2000);
DriverScript.bResult = true;
DriverScript.Message = "Slide " + ElementLocator;
}catch(Exception e){
Log.error("Not able to Slide--- " + e.getMessage());
DriverScript.Message = "Not able to Slide--- " + e.getMessage();
DriverScript.bResult = false;
}
}
public static void SetStyle(String ElementLocator, String data){
try{
Log.info("Set Style of Web element"+ElementLocator);
Thread.sleep(2000);
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.xpath(ElementLocator));
js.executeScript("arguments[0].setAttribute('style', data)",element);
DriverScript.Message = "Set Stlye of Web element"+ElementLocator;
DriverScript.bResult=true;
}catch(Exception e){
Log.error("Not able to set stlye --- " + e.getMessage());
DriverScript.Message = "Not able to set style --- " + e.getMessage();
DriverScript.bResult = false;
}
}