Xpath for date in makemytrip.com

170 views
Skip to first unread message

Akshay Goel

unread,
Jun 30, 2019, 10:30:18 AM6/30/19
to seleniu...@googlegroups.com
Hi All,

I want xpath for departure date which will be year independent. 
URL:-  https://www.makemytrip.com/  

Best Regards,
Akshay Goel

John Doe

unread,
Jul 1, 2019, 9:30:19 AM7/1/19
to Selenium Users
Looking into page DOM it appears that there is a label having for attribute of location

foo.png


So the relevant XPath query would be something like:


//label[@for='departure']


 I would also recommend using Explicit Wait in order to wait until the label will appear in DOM. 


Example code:


package com.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class TestClass {

@Test
public void someTest() throws Exception {
System.setProperty("webdriver.chrome.driver", "c:/apps/webdriver/chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.makemytrip.com/ ");
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement departure = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//label[@for='departure']")));
System.out.println(departure.getAttribute("innerText"));
driver.quit();
}
}



Demo:


bar.png


More information: How to use Selenium to test web applications using AJAX technology



Reply all
Reply to author
Forward
0 new messages