user2377826:
Estoy tratando de hacer clic en el valor desplegable para seleccionar la ciudad desde el jardín de hacer mi viaje http://www.makemytrip.com/ . Pero se desgaste excepción de referencia elemento. Ids se están cambiados al cargar la página. Intentado por debajo de código:
driver.findElement(By.xpath(".//*[@id='hp-widget__sfrom']")).clear();
driver.findElement(By.xpath(".//*[@id='ui-id-1']"));
driver.findElement(By.xpath(".//*[@id='hp-widget__sfrom']")).click();
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeSelected(driver.findElement(By.xpath(".//*[@class='ui-menu-item'][2]"))));
DebanjanB:
Para hacer clic en un valor desplegable por ejemplo, Mumbai se puede utilizar la siguiente solución:
Bloque de código:
driver.get("https://www.makemytrip.com/") new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='input_fromto checkSpecialCharacters ui-autocomplete-input' and @id='hp-widget__sfrom']"))).click(); List<WebElement> myList = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//li[@class='ui-menu-item'][starts-with(@id,'ui-id-')]//span[@class='autoCompleteItem__label']"))); for (WebElement element:myList) if(element.getText().contains("Mumbai")); element.click();
Navegador de instantáneas: