1

I was trying to automate the Make My Trip site using Selenium. These are the steps I took:

  1. Search for MakeMyTrip in Google -> Done
  2. Open makemytrip and change country to US -> Done
  3. Click on feedback -> Done
  4. Trying to fill feedback form -> Error

It's saying, unable to find the element.

I have tried the following: 1. Tried finding the element by id 2. Tried finding the element by xpath

//div[@class='feedback-form-container']//form[@id='feedbackForm']//input[@id='field_name_NAME']"

Code:

public void setUp() throws Exception {
        driver = new FirefoxDriver();
        baseURL = "http://www.google.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }


    @Test
    public void makeMyTriptest() throws Exception {
        System.out.println("Entered this loop");
        driver.get(baseURL + "/?gws_rd=ssl");
        driver.findElement(By.id("lst-ib")).sendKeys("makemytrip");

        System.out.println("send keys successful");

        driver.findElement(By.linkText("Flights - MakeMyTrip")).click();
        driver.findElement(By.id("country_links")).click();
        driver.findElement(By.xpath("//*[@id='country_dropdown']//p//a[@href='http://us.makemytrip.com/']")).click();
        driver.findElement(By.xpath("//div[@id='webklipper-publisher-widget-container-content-expand-collapse']")).click();

        //entering feedback details
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        //driver.findElement(By.id("field_name_NAME")).sendKeys("SubbaRao");
        driver.findElement(By.xpath("//div[@class='feedback-form-container']//form[@id='feedbackForm']//input[@id='field_name_NAME']")).sendKeys("SubbaRao");
        //driver.findElement(By.id("field_email_EMAIL")).sendKeys("test@test.com");

    }
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
SubbaRao P
  • 63
  • 1
  • 1
  • 5
  • If you check the HTML, the feedback form is opened into an iframe. See http://stackoverflow.com/a/25809942/136363 – t0mppa Oct 10 '15 at 17:40

1 Answers1

0

The Feedback form is located inside an iframe. You have to switch into it's context:

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//WebElement iFrame = driver.findElement(By.xpath("//*[id='print_ticket_overlayiframe']"));
driver.switchTo().defaultContent();
driver.switchTo().frame("webklipper-publisher-widget-container-frame");
//driver.findElement(By.id("field_name_NAME")).sendKeys("SubbaRao");
driver.findElement(By.xpath("//*[@id='field_name_NAME']")).sendKeys("SubbaRao");

now while you are in the iframe, search for the input

Works for me.

enter image description here

JeffC
  • 22,180
  • 5
  • 32
  • 55
Mona
  • 342
  • 1
  • 3
  • 17
  • 1
    Enjoy!! keep sharing knowledge. BTW if it worked. accept as solution. it may hlp others. – Mona Oct 11 '15 at 13:16