简体   繁体   中英

how to fix “could not be scrolled into view” error in Selenium Python

I am scrolling an element into view via JavaScript, but when trying to click on that element an exception is being raised which says the element cannot be scrolled into view, but when I look at the browser, it has been scrolled into view. I've even tried waiting for the item to be clickable but the same error is still thrown.

I'd appreciate it if anyone could provide any solutions in python, but java is okay. Thanks you. :)

Here is my code:

for i in range(len(units)):
    matchCnt += '0'
    for name in className:
        if name.lower() in str(units[i].text).lower():
            matchCnt[i] = str(int(matchCnt[i]) + 1)
            if int(matchCnt[i]) == len(className):
                browser.execute_script('return arguments[0].scrollIntoView(true);', units[i])
                WebDriverWait(browser, 200).until(EC.element_to_be_clickable((By.CLASS_NAME, classId)))
                #element[i].click()
                #WebDriverWait(browser, 200).until(webdriver.support.expected_conditions.element_to_be_clickable(units[i]))
                #time.sleep(5)
                units[i].click()
                doesMatch = True
    if doesMatch:
        break

您可以使用Javascript单击该单元,通过这种方式,元素将被单击,但不会滚动元素到视图中。

driver.execute_script("arguments[0].click();",unit[i])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM