Babita Sethi
Babita Sethi

Reputation: 19

How to SendKeys in Selenium for my Website

I am trying to automate a page [Link]https://qlb21.resources.hewitt.com/cl77ybr5qc/ybr5cl772b/CsLogn010InptOpen.do?fTkn=539f4eddc99aef9eb1c8da11d13a3654&fWdw=intro&eWlmYBR5ClntId=00398&wdw=primary&fPg=%2FCsLogn005WelcOpen. After clicking on the above link you will get a prompt.That prompt now i am able to handle 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

`

    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.PageFactory;

    import com.selenium.commons.Configuration;

     public class Home {
     public WebDriver driver = Configuration.driver;


@FindBy(id="usrId")
private WebElement user;

@FindBy(id="pswd")
private WebElement pswd;

@FindBy(id="tranId'")
private WebElement tranId;

@FindBy(id="logOn")
private WebElement logOn;

public Home()
{       
    PageFactory.initElements(Configuration.driver, this);

}

public void logon(String Username,String Password,String trns)
{
    Configuration.driver.get(Configuration.URL);
    Configuration.driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);

    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("Babita Sethi");

}

`

Upvotes: 1

Views: 318

Answers (2)

snigdha
snigdha

Reputation: 26

That prompt is in iframe. but home page is not in iframe. Whenever if you want to perform actions on homepage you should switch back to the default content. i.e driver.switchTo().defaultContent();

Upvotes: 0

Erki M.
Erki M.

Reputation: 5072

You should switch back from iframe as well, before doing the user name field lookup, do something like:

driver.switchTo().defaultContent();

Upvotes: 3

Related Questions