Different Way of Click in Selenium WebDriver


 /*    Click on Element using Actions class's click method*/
 public void actionClick(String xpathValue) throws NoSuchElementException, Exception
 {
  WebElement element = driver.findElement(By.xpath(xpathValue));
  new Actions(driver).moveToElement(element).click().build().perform();
 }

 /*    Click on Element */
 public void clickMethod(String xpathValue) throws NoSuchElementException, Exception {
  WebElement element = driver.findElement(By.xpath(xpathValue));
  element.click();
 }

 /*    Click on Element using JavascriptExecutor class's click method (Using JavaScript)*/
 public void javaScriptClick(String xpathValue) throws NoSuchElementException, Exception {
  WebElement element = driver.findElement(By.xpath(xpathValue));
  JavascriptExecutor js = (JavascriptExecutor) driver;
  js.executeScript("arguments[0].click();", element);
 }

 /*    Perform Mouser Hover on Element and Click on other  Element*/
 public  void mouseHoverAndClick(WebElement elementToHover,WebElement elementToClick) {
  Actions action = new Actions(driver);
  action.moveToElement(elementToHover).click(elementToClick).build().perform();
 }

 /* Perform Mouser Hover on Element */
 public void mouseHover(WebDriver driver, WebElement element) {
  Actions action = new Actions(driver);
  action.moveToElement(element).perform();
 }

/* Perform Double Click on Element*/
     public void mouseHover (WebElement element) {                                                               
     Actions action = new Actions(driver).doubleClick(element);                               
     action.build().perform();
 }



Post a Comment

0 Comments