https://www.goibibo.com/hotels/ Image
I want to select one city using selenium, but its not working I have tried with xpath, css selector, id, className.\
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Goibibo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver_2\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//Goto Url Goibibo.com
driver.get("https://www.goibibo.com/hotels/");
System.out.println("WWW.GOIBIBO.COM");
//Select Country India
driver.findElement(By.xpath("//input[@name='CountryType']")).click();
System.out.println("Selected Country India");
// Click on Search Bar
driver.findElement(By.id("downshift-1-input")).click();
System.out.println("Clicked On Search Bar");
//Select Mysore City
driver.findElement(By.xpath("//*[@id=\"downshift-1-menu\"]/div/ul/li[2]/img")).click();;
}
}
You can try with the below xpath :
//p[text()='Mysore']
or
//img[contains(@alt,'Mysore')]/following-sibling::div
in code :
System.out.println("Clicked On Search Bar");
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//p[text()='Mysore']"))).click();
System.out.println("Task has been done !");