-2

Below Is the site page

Banking Netbanking Page

I'm trying to click on Continue to Netbanking button. But I am unable to do that. I have used xpath but its not working. Here is xpath which I've tried :

driver.findElement(By.xpath(".//*[@id='wrapper']/div[6]/a/img")).click();

Steps:

  1. Open URl http://www.hdfcbank.com
  2. Click on Login button on website. New popup will get open.
  3. Click on "Continue on Netbanking". THIS IS NOT WORKING

Here is code:

driver.findElement(By.id("loginsubmit")).click();

    Thread.sleep(3000);

    Set<String> set = driver.getWindowHandles();
    Iterator<String> it = set.iterator();
    System.out.println(set.size());

    for( String windowTab : set){
        if(!windowTab.equalsIgnoreCase(MainWindow)){
            driver.switchTo().window(it.next());
            driver.manage().window().maximize();
            String Wdinw2 = driver.getWindowHandle();
            Thread.sleep(10000);
            System.out.println(driver.getTitle());

            driver.findElement(By.xpath(".//*[@id='wrapper']/div[6]/a/img")).click();

            break;
        }

    }

Console :

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='wrapper']/div[6]/a/img"}

NarendraR
  • 7,577
  • 10
  • 44
  • 82
Praveen Kumar
  • 53
  • 1
  • 9
  • I am just curious to know whey there is a **dot** before //*[@id='wrapper'] – shank087 Feb 08 '17 at 06:03
  • I guess you have to first move to another window, because when click on login button"Continue to NetBanking" button is showing inside another window. then try it with your xpath element. – Jainish Kapadia Feb 08 '17 at 06:06
  • 1
    did you handle the change to the pop up window? http://stackoverflow.com/questions/19403949/how-to-handle-pop-up-in-selenium-webdriver-using-java – Matts Feb 08 '17 at 06:07
  • Assuming that you have permission to perform automation testing for this bank site. Financial websites especially banks are pretty paranoid about any automated access. – Grasshopper Feb 08 '17 at 06:45

1 Answers1

4

Try to use below code and let me know the result:

String winHandleBefore = driver.getWindowHandle();
for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);}

WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("img[alt='continue']"))).click();

To switch back to main window (if you need):

driver.switchTo().window(winHandleBefore);
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • 1
    Agree with @andersson code, also if you want to click "contuie to NetBanking" button with xpath. you can use this way. `(By.xpath("//img[@src='/assets/images/netbanking_continue_red.gif']")).click();` – Jainish Kapadia Feb 08 '17 at 06:16