Một vài cách không chạy được:
- Điền trực tiếp “Hanoi,Vietnam” vào thẻ input
- Điền “Hanoi” rồi click vào cái ô suggestion bên dưới (element not interactable)
Đáp án:
- Click vào ô City Name –> trang web sẽ tạo ra 1 thẻ input ở phía cuối của DOM.
- Điền “Hanoi” vào thẻ input
- Ấn Enter
driver.findElement(By.id("select2-hotels_city-container")).click(); Thread.sleep(2000); driver.findElement(By.cssSelector("input.select2-search__field")).sendKeys("Hanoi"); Thread.sleep(2000); driver.findElement(By.cssSelector("input.select2-search__field")).sendKeys(Keys.ENTER);
Ở giữa các step mình dùng Thread.sleep()
, bạn có thể thay thế bằng Explicit Wait tương ứng.