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:
- Why did the Firebug generated xpath fail?
- 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– DEnumber502015年07月01日 19:26:17 +00:00Commented Jul 1, 2015 at 19:26
-
not as of now. I will be trying using CSSdemouser123– demouser1232015年07月02日 02:25:19 +00:00Commented Jul 2, 2015 at 2:25
1 Answer 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– demouser1232015年07月02日 06:57:16 +00:00Commented Jul 2, 2015 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– demouser1232015年07月02日 14:05:17 +00:00Commented Jul 2, 2015 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 whydemouser123– demouser1232015年07月02日 14:07:04 +00:00Commented Jul 2, 2015 at 14:07
-
Could you please provide your HTML ? It's easier to help me understand your issue?scorpion– scorpion2015年07月03日 03:54:52 +00:00Commented Jul 3, 2015 at 3:54
Explore related questions
See similar questions with these tags.