0

I am trying to login to this site

But when the page loads it shows a frame.

I tried to switch to frame but all in vain

public void logon(String Username,String Password,String trns)
{
    Configuration.driver.get(Configuration.URL);

    Configuration.driver.manage().timeouts().implicitlyWait(8,TimeUnit.SECONDS);
    Configuration.driver.switchTo().
    //Configuration.driver.findElement(By.xpath("//a[@text()='Close Window']")).click();
    usrId.sendKeys("Username");
    pswd.sendKeys("Password");
    tranId.sendKeys("trns");
    logOn.click();
}
Madhan
  • 5,750
  • 4
  • 28
  • 61
Ketan Sethi
  • 124
  • 2
  • 9
  • Welcome to StackOverflow. Please read: [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask).And post what have you tried – Madhan Jul 17 '15 at 19:32
  • Refer [this](http://stackoverflow.com/questions/20069737/how-to-identify-and-switch-to-the-frame-in-selenium-webdriver-when-frame-does-no/20181195#20181195) – Madhan Jul 17 '15 at 19:39

1 Answers1

0

You can easily get code for Frame switch. Please search for the question before posting it.

//Switch to Iframe
 WebElement iframe = driver.findElement(By.xpath("Xpath of frame"));
 driver.switchTo().frame(iframe);  

 //Perform your Task.

 driver.switchTo().defaultContent();// Iframe is Switched to Main Again 

Check this links for frame Switch:- Click here

Hi Ketan. The problem with your code might be wait issue. Once you click on continue button in the pop-up window, it requires some time interact with the next element. So for those you need to declare some with in your code.

Check this link for waits

Here is the working code. I tried it. please check this, it will resolve your problem.

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.support.ui.Select;

public class userId {

    public static void main(String[] args) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("https://qlb21.resources.hewitt.com/cl77ybr5qc/ybr5cl772b/CsLogn010InptOpen.do?fTkn=539f4eddc99aef9eb1c8da11d13a3654&fWdw=intro&eWlmYBR5ClntId=00398&wdw=primary&fPg=%2FCsLogn005WelcOpen");
        System.out.println("Entered Url");
        WebElement frame=driver.findElement(By.xpath("//*[@id='lightbox_iframe_cookieBanner']"));
        driver.switchTo().frame(frame);
        driver.findElement(By.xpath("//*[@id='lightboxarea']/div/div/a[1]")).click();
        driver.switchTo().defaultContent();
        driver.findElement(By.xpath("//*[@id='usrId']")).sendKeys("hari");
        System.out.println("Entered the userid");
        driver.findElement(By.xpath("//*[@id='pswd']")).sendKeys("Password");
        System.out.println("Entered the Password");    
    }
}
Hari kishen
  • 463
  • 2
  • 9
  • Hi @Hari Kishen thanks for the support i am able to handle the frame...Can you please also tell how to sendkeys in the UserID textbox because i tried a lot and didn't got any result in the website [Link]https://qlb21.resources.hewitt.com/cl77ybr5qc/ybr5cl772b /CsLogn010InptOpen.do?fTkn=539f4eddc99aef9eb1c8da11d13a3654&fWdw=intro&eWlmYBR5ClntId=00398&wdw=primary&fPg=%2FCsLogn005WelcOpen – Ketan Sethi Jul 18 '15 at 18:00
  • public void logon(String Username,String Password,String trns) { Configuration.driver.get(Configuration.URL); try{ Thread.sleep(10000); } catch(Exception e) { } Configuration.driver.switchTo().frame(Configuration.driver.findElement(By.xpath("//iframe[@id='lightbox_iframe_cookieBanner']"))); Configuration.driver.findElement(By.xpath("//a[text()='Continue']")).click(); driver.manage().window().maximize(); System.out.println(driver.getTitle()); driver.findElement(By.id("usrId")).sendKeys("Unable to Login"); } – Ketan Sethi Jul 18 '15 at 18:03
  • Can you provide me the website link, where you are trying? – Hari kishen Jul 18 '15 at 18:14
  • Thanks! for replying.. The Link is [link](https://qlb21.resources.hewitt.com/cl77ybr5qc/ybr5cl772b/CsLogn010InptOpen.do?fTkn=539f4eddc99aef9eb1c8da11d13a3654&fWdw=intro&eWlmYBR5ClntId=00398&wdw=primary&fPg=%2FCsLogn005WelcOpen) Note: After clicking on the above link you will get a prompt.That prompt now i am able to handle(with your help on how to handle the frame) but after clicking on continue button on the iframe the Home Page is showing userid and password on that UserId textbox i tried to send using sendkeys but in vain driver.findElement(By.id("usrId")).sendKeys("Unable to Login"); – Ketan Sethi Jul 19 '15 at 03:16
  • Hi Ketan - I have given the working code, which will resolve your problem. Please check it in the answer section and also don't forget to Accept my Answer. Thanks. – Hari kishen Jul 19 '15 at 16:15
  • Thanks! so much i am getting the expected results :) – Ketan Sethi Jul 25 '15 at 04:25