no such element: Unable to locate element using chromedriver and Selenium in production environment

后端 未结 4 530
故里飘歌
故里飘歌 2021-01-04 13:29

I have a problem with selenium chromedriver which I cannot figure out what\'s causing it. Some weeks ago everything was working OK, and suddenly this error started to show u

4条回答
  •  被撕碎了的回忆
    2021-01-04 14:02

    You need to wait until the element is visible or else you will get this error. Try something like this:

    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support.expected_conditions import visibility_of_element_located
    from selenium.webdriver.common.by import By
    TIMEOUT = 5
    
    ...
    xpath = '//*[@id="sidebar"]/ul/li[1]/a'
    WebDriverWait(self.selenium, TIMEOUT).until(visibility_of_element_located((By.XPATH, xpath)))
    browser.find_element_by_xpath(xpath)
    ...
    

提交回复
热议问题