Scrapy + Selenium + Datepicker

给你一囗甜甜゛ 提交于 2020-01-03 03:33:06

问题


So i need to scrap a page like this for example and i am using Scrapy + Seleninum to interact with the datepicker calendar but i am running into a ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with.

So far i have:

def parse(self, response):

    self.driver.get("https://www.airbnb.pt/rooms/9315238")
    try:
        element = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.XPATH, "//input[@name='checkin']"))
        )
    finally:
        x = self.driver.find_element_by_xpath("//input[@name='checkin']").click()
        import ipdb;ipdb.set_trace()
        self.driver.quit()

I saw some references on how to achieve this https://stackoverflow.com/a/25748322/977622 and https://stackoverflow.com/a/19009256/977622 .

I appreciate if someone could help me out with my issue or even provide a better example on how i can interact the this datepicker calendar.


回答1:


There are two elements with name="checkin" - the first one that you actually find is invisible. You need to make your locator more specific to match the desired input. I would also use the visibility_of_element_located condition instead:

element = WebDriverWait(self.driver, 10).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, ".book-it-panel input[name=checkin]"))
)


来源:https://stackoverflow.com/questions/35799855/scrapy-selenium-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!