While i tried automating a website using selenium and Java i got no such element exception even though i got correct xpath while inspecting the field. After giving a city by sendkeys i tried to select 1st option from dropdown by select method and actions keyword but both didnt work and throwed exception. I will attach the code and image of inspected website.Kindly help with the issue
@Test
public void abhibusHotel() throws Exception {
driver.get("https://www.abhibus.com/");
HomePage ohome=new HomePage(driver);
ohome.hotelPage();
HotelBooking obook=new HotelBooking(driver);
obook.bookingDetails();
Thread.sleep(2000);
public void bookingDetails()
{
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(city)).sendKeys("Bengaluru");
//Select se=new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//span[text()='Beng'])[1]/parent::div"))));
//Select se=new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Beng'][1]"))));
//se.selectByIndex(1);
WebElement tooltip= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Beng']/parent::div")));
oaction.moveToElement(tooltip).click().build().perform();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
question from:
https://stackoverflow.com/questions/66067923/no-such-element-exception-in-selenium-code-using-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…