Airbnb - selenium - filter price input box sets value by visual if clicked off

Viewed 41

I'm trying to do some scraping of airbnb's website for a small project. Using selenium to try to filter results by price I stumbled upon an issue. I select the max price input box by xpath, then give it a little WebElement.clear(). however when I try to do a WebElement.send_keys(price), it gets the price from the visual sliding bar or sets it to max price and ignores my input. It's the same action that happens if you clear the field and then click off it. Anyone have experience with this?

1 Answers

This is how to do it using Python:

filter = driver.find_element(By.Xpath, '//span[contains(text(),"Filters")]')
filter.click
max_price = driver.find_elemnet(By.Css, 'input[id="price_filter_max"]'
max_price.clear()
max_price.click()
max_price.send_keys('100')
show_btn = driver.find_element(By.Xpath, '//a[contains(text(),"Show")]')
show_btn.click()

If that's is not working for you, you can mimic a simple keyboard press. Do this after you click the element via Selenium:

ActionChains(driver)\
        .send_keys("100")\
        .perform()
Related