1

I have found several questions related to this one particular travel website MakeMyTrip, so I tried to automating it.

I was successful in selecting the primary details and getting on the Flight listings page.

I wanted to select the cheapest flight combination out of the available options. Now the website has an option, which always shows the lowest flight combination. I was hoping to use it to book the flight.

Flight Listings

Now, the way I thought was doing this-

  • Recognising that the cheapest Flights tab is present- using present_of_element_located expected conditions.
  • Clicking on the Book button to get to next page.

The issue I am facing is recognizing the Cheapest Flight tag. I tried to recognize it by xpath, but the test failed because it didn't find the element. I am using Firebug to check the xpath, and it comes as

//*[@id='content']/div/div[2]/div/div/div[3]/div[4]/a[2]

I also tried this xpath,

//div[@class='stk_btm_toptabs']//a[@class='stk_btm_chpFlight'][text='cheapest Flights']

but failed both times.

My question here is:

  1. Why did the Firebug generated xpath fail?
  2. Mistake in my xpath

Also I tried removing these checks to directly click on book button but it is also failing, probably because the tag comes a tad second after the page loads. And that is why I was thinking of waiting until the time the tag is loaded and visible on the page.

Here is the piece of code :

        WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.XPATH, "//div[@class='clearfix']//a[@class='stk_btm_chpFlight'][text='cheapest Flights']")))

    bookbtn=driver.find_element_by_xpath("//*[@id='content']/div/div[2]/div/div/div[3]/div[3]/div/div[2]/span/span[2]/a")
    bookbtn.click()
  • Have you tried any other element method than an xpath? – DEnumber50 Jul 1 '15 at 19:26
  • not as of now. I will be trying using CSS – demouser123 Jul 2 '15 at 2:25
1

Is your element placed inside an iFrame? If it's in iFrame, you should switch driver to that iFrame first and then try to access the element.

OR

You could also try accessing the element with

element = driver.findElement(By.cssSelector("div.clearfix.stk_btm_toptabs.text-center>a.stk_btm_chpFlight.active"));
  • ok haven't thought about the iframe thing. how do i recognize if its in iframe or not. – demouser123 Jul 2 '15 at 6:57
  • thanks @scorpion the css selector worked. I have one more doubt regarding the button. I went through the css selector you mentioned and created one for the button- – demouser123 Jul 2 '15 at 14:05
  • div.col-xs-7>span.stk_btm_earnpoint.pull-right>a.btn.btn-lg.pull-right.btn-primary-red but it doesn't seem to work ? Any idea why – demouser123 Jul 2 '15 at 14:07
  • Could you please provide your HTML ? It's easier to help me understand your issue? – scorpion Jul 3 '15 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.