1

On website https://www.expedia.com/ i need to type on the Leaving from colum,but it only gives me an error:AttributeError: 'NoneType' object has no attribute 'send_keys'. How can i write on Leaving from?

import time

from selenium import webdriver


driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver")

driver.implicitly_wait(5)

driver.maximize_window()

driver.get("https://www.expedia.com/")
driver.find_element_by_xpath("//span[text()='Flights']").click()

time.sleep(2)
driver.find_element_by_xpath("//*[@id=wizard-flight-tab-roundtrip]/div[2]/div[1]/div/div[1]/div/div/div/button").send_keys("SFO")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
NikaTheKilla
  • 115
  • 2
  • 11

2 Answers2

1

To send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get("https://www.expedia.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[aria-controls='wizard-flight-pwa']>span"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[aria-label='Leaving from']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#location-field-leg1-origin"))).send_keys("SFO")
    
  • Using XPATH:

    driver.get("https://www.expedia.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@aria-controls='wizard-flight-pwa']//span"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@aria-label='Leaving from']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='location-field-leg1-origin']"))).send_keys("SFO")
    
  • Browser Snapshot:

expedia_from_SFO

  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

It seems like your last "find_element_by_xpath" does not correctly locate the element you are looking for. An xpath that does locate your element is

"//input[@id='location-field-leg1-origin-input']"

I don't think this will completely solve your problem though. One thing is that you need to click on this element rather than simply send keys to it. You need to open the modal where you actually enter and select the airport you are leaving from.

inteoryx
  • 785
  • 2
  • 9
  • Tried it. Error: ElementNotInteractableException: Message: element not interactable – NikaTheKilla Nov 17 '21 at 07:32
  • Yes, as I mentioned you cannot type on that element. The website wants you to interact with it to open the modal where you do type and select an airport. – inteoryx Nov 17 '21 at 07:34
  • Ok i tried just with click() but the error message is: Message: element not interactable. river.find_element_by_xpath("//input[@id='location-field-leg1-origin-input']").click() – NikaTheKilla Nov 17 '21 at 07:42