Reputation: 186
Here is the website - https://www.phptravels.net/m-hotels
I am not able to find the field called the city field(see attached screenshot) Even the selenium is not able to record that field. I want to enter the text in that field.
This is what i have tried but it is not working:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.phptravels.net/m-hotels")
a = driver.find_element_by_class_name("select2-choice")
a.click()
city = driver.find_element_by_css_selector(".select2-input.select2-focused")
city.send_keys("Test")
Upvotes: 0
Views: 329
Reputation: 19154
another alternative, using xpath
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.phptravels.net/m-hotels")
a = driver.find_element_by_class_name("select2-choice")
a.click()
city = driver.find_elements_by_xpath('(//*[@id="select2-drop"]/div/input)')
city[0].send_keys("Jakarta")
Upvotes: 1
Reputation: 52665
Try to use below code:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.phptravels.net/m-hotels")
wait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Search by Hotel or City Name"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#select2-drop .select2-input"))).send_keys("Test")
Upvotes: 1