0
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class HDFCBank {

public static void main(String[] args) {

     WebDriver driver=new FirefoxDriver();
     driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
     driver.get("http://www.hdfcbank.com/");
     Actions action=new Actions(driver);
     WebElement productsLink=driver.findElement(By.xpath("//span[text()='Products']"));
     action.moveToElement(productsLink).perform();
     try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     WebElement cardLink=driver.findElement(By.xpath("//span[text()='Cards']"));
     action.moveToElement(cardLink).perform();
     try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
     WebElement creditcardLink=driver.findElement(By.xpath("//a[contains(text(),'Credit Cards')]"));
     action.moveToElement(creditcardLink).perform();
     try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
     //action.click(creditcardLink).perform();
     creditcardLink.click();

     WebElement customerLink=driver.findElement(By.xpath("//span[text()='Apply now']"));
     action.moveToElement(customerLink).perform();

     WebElement propertyLink=driver.findElement(By.xpath("//div[@class='lhssection']//a[text()='Loan Against Property']"));
     action.moveToElement(propertyLink).perform();
     action.click(propertyLink).perform();
  }
 }

a)The mouse pointer moves to Products->Cards->Credit Cards of the header, but it is not clicking the Credit Card link even though ive put the statments, can any one tell me how to click on the Credit Card link.

b)The mouse moves to the Apply Now of the header but fails to move over Loan Against Property(as per the code) giving an MoveTargetOutOfBoundsException,why is this exception caused and how do i resolve this?

Manigandan
  • 5,004
  • 1
  • 28
  • 47
user3296744
  • 169
  • 3
  • 9
  • For the a) point, did you try action.click(creditcardLink).perform(); ? – Tony Apr 17 '14 at 11:59
  • yes i did, it didnt work :( – user3296744 Apr 17 '14 at 12:00
  • For 2nd point, is the desired element in view? If not you will have to scroll to that part before mouse hover. – Husam Apr 17 '14 at 12:11
  • For 1st point - you can always use javascript, you wont even have to mouse over to so many elements. You can just click it directly using javascript even if the element is not visible on page. – Husam Apr 17 '14 at 12:16
  • 1st point - it worked for me in Chrome (although it didn't in FF). Maybe you should raise a bug against FF driver. – JacekM Apr 17 '14 at 16:29
  • @Husam how do i do it using javascript? – user3296744 Apr 18 '14 at 14:33
  • [How to click a button in Selenium WebDriver using JavaScript](http://stackoverflow.com/questions/11947832/how-to-click-a-button-in-selenium-webdriver-using-javascript) – Husam Apr 18 '14 at 19:22

0 Answers0