0

I am new to web scrapping. I am trying to scrape a website (for getting flight prices) using Python Selenium which has some drop down menu for fields like departure city, arrival city. The first option listen should be accessed and used.

Lets say that the field departure city is button, on click of that button, a new html page will be loaded with input box and a list set is available with every list element consisting of a button.

While debugging I found that, once my keyword is entered the options loading screen appears but options are not getting loaded even after increasing the sleep time (I have attached the image for the same). image with error Manually there are no issues with the drop down menu. As soon as I enter my departure city, options will be loaded and I choose the respective location.

I also tried to use actionchains. Unfortunately there is no luck. I am attaching my code below. Any help is appreciated.

#Manually trying to access the first element:**

#Accessing Input Field:** 

fly_from = browser.find_element("xpath", "//button[contains(., 'Departing')]").click()

element = WebDriverWait(browser,10).until(ec.presence_of_element_located((By.ID,"location")))

#Sending the keyword:**
element.send_keys("Los Angeles")

#Selecting the first element:**
first_elem = browser.find_element("xpath", "//div[@class='classname default-padding']//div//ul//li[0]]//button")

Using Action Chains:

fly_from = browser.find_element("xpath", "//button[contains(., 'Departing')]").click()

time.sleep(10)

element = WebDriverWait(browser, 10).until(ec.presence_of_element_located((By.ID, "location")))

element.send_keys("Los Angeles")

time.sleep(3)

list_elem = browser.find_element("xpath", "//div[@class='class name default-padding']//div//ul//li[0]]//button")

size=element.size

action = ActionChains(browser)

action.move_to_element_with_offset(to_element=list_elem,xoffset =0.5*size['width'], yoffset=70).click().perform()



action.click(on_element = list_elem)

action.perform()
Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30

0 Answers0