ElementNotInteractableException: Message: Element could not be scrolled into view while trying to click an element using Selenium and Python

前端 未结 3 844
無奈伤痛
無奈伤痛 2021-01-25 00:06

I have this code:

driver.switch_to.window(window_after)

try:
    myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.NAME, \'_eventId         


        
3条回答
  •  一生所求
    2021-01-25 00:19

    Here are the 2 options.

    Using selenium location_once_scrolled_into_view method:

    btn.location_once_scrolled_into_view
    

    Using Javascript:

    driver.execute_script("arguments[0].scrollIntoView();",btn)
    

    Sample Code:

    url = "https://stackoverflow.com/questions/55228646/python-selenium-cant-sometimes-scroll-element-into-view/55228932?    noredirect=1#comment97192621_55228932"
    driver.get(url)
    element = driver.find_element_by_xpath("//a[.='Contact Us']")
    element.location_once_scrolled_into_view
    time.sleep(1)
    driver.find_element_by_xpath("//p[.='active']").location_once_scrolled_into_view
    driver.execute_script("arguments[0].scrollIntoView();",element)
    

提交回复
热议问题