Reputation: 21
I am new to selenium and written a basic test to launch a website, click on link, fill form and submit.
Once it reaches to sign up page it is unable to find the "FirstName" text box. I double checked using the firebug and it is available only at one place. I even tried to identify element with xpath still getting the same error.
Here is the code using the xPath to identify first name text box.
package Default;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
//import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstWDWithoutRecording {
@Test
public void SouthWestSignUp() throws InterruptedException
{
//Open the FF/Chrome browser
//FirefoxDriver oBrw = new FirefoxDriver();
ChromeDriver oBrw = new ChromeDriver();
//Maximize Browser
oBrw.manage().window().maximize();
//Open/Launch www.southwest.com
System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
oBrw.get("http://www.southwest.com/");
//Click on Sign up and Save
//Recognising
oBrw.findElement(By.linkText("Sign up")).click();
Thread.sleep(7000);
//Enter First Name
oBrw.findElement(By.xpath("//input[@id='FIRST_NAME']")).clear();
oBrw.findElement(By.xpath("//input[@id='FIRST_NAME']")).sendKeys("abc");
//Enter Last Name
oBrw.findElement(By.id("LAST_NAME")).clear();
oBrw.findElement(By.id("LAST_NAME")).sendKeys("Kish123");
//Enter Email ID
oBrw.findElement(By.id("EMAIL")).clear();
oBrw.findElement(By.id("EMAIL")).sendKeys("[email protected]");
//Selecting Home Airport
Select uiHomeAp = new Select(oBrw.findElement(By.id("HOME_AIRPORT")));
uiHomeAp.deselectByVisibleText("Atlanta, GA - ATL");
//Accepting Conditions
oBrw.findElement(By.id("IAN")).click();
//Click Submit
oBrw.findElement(By.id("submit")).click();
}
}
Upvotes: 0
Views: 134
Reputation: 5453
Your sign up form is located within an <iframe>
. For Webdriver to be able to 'see' the form you'll first need to switch to that iframe.
driver.switchTo().frame(0); //'0' as it is the only iframe on the page, the value is the index of all iframes on the page
//do your login actions
//after return
driver.switchTo().defaultContent();
Upvotes: 2