0

I am getting an issue while automating www.expedia.com**. I am a beginner and learning to automate the website.

I am getting this error, and I am selecting the right element using "chropath" extension. Could anyone from the forum guide me.

Traceback (most recent call last):
  File "c:/Users/test/Documents/Python3.6/Python-youtube/test.py", line 29, in <module>
    driver.find_element_by_xpath("//li[3]//button[1]").click()
 
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()
driver.get("https://www.expedia.com")
driver.maximize_window()

driver.find_element_by_xpath("//span[contains(text(),'Flights')]").click()

# Origin
driver.find_element_by_class_name('uitk-faux-input').click()
driver.find_element_by_xpath("//input[contains(@placeholder,'Where are you leaving 
from?')]").send_keys('florida')
driver.find_element_by_xpath("//li[2]//button[1]").click()

# Destination
driver.find_element_by_xpath
(
 "//div//div//div//div//div//div//div//div//div//div//div//div//div
  //div//div//div//div//div//div//div//div[2]//div[1]//div[1]//div[1]//button[1]").click()
driver.find_element_by_xpath("//input[contains(@placeholder,'Where are you going 
to?')]").send_keys('vancouver')
driver.find_element_by_xpath("//li[3]//button[1]").click()

Please advice.

Neo Anderson
  • 5,957
  • 2
  • 12
  • 29
  • See this, it helped me more than once: https://stackoverflow.com/questions/44119081/how-do-you-fix-the-element-not-interactable-exception/44119817 – Suyash Sep 12 '20 at 07:43

1 Answers1

0

The problem is that //li[3]//button[1] matches 2 elements and the first one is hidded. You need to change locator.

For example, use this code:

locator = "//li[3]//button[@data-stid='location-field-leg1-destination-result-item-button']//div[@class='truncate']"
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, locator)))
driver.find_element_by_xpath(locator).click()

instead of:

driver.find_element_by_xpath("//li[3]//button[1]").click()

P.S. //div//div//div//div//div//div//div//div//div//div//div//div//div //div//div//div//div//div//div//div//div[2]//div[1]//div[1]//div[1]//button[1] it is very very very bad locator:)