我有一个 html 为 list
- <ul><li><a></a></li>...
的下拉列表
此下拉列表是可滚动的,我需要使 Selenium
滚动到具有某些 <a>
的 id
,因为除非它可见,否则我无法单击它。
使用 JavaScript
可能是可能的,但不知道如何让它工作。
clickable_a_id - id of <a> element which I want to scroll to
self.driver.execute_script(
# 'arguments[0].scrollTop = document.getElementById("{}").offsetTop + 5 '.format(clickable_a_id),
'document.getElementById("{}")[0].scrollIntoView()'.format(clickable_a_id),UL_ELEMENT)
它不起作用。你知道该怎么做吗?
最佳答案
您尝试过使用操作吗?
el = driver.find_element_by_xpath("")
webdriver.ActionChains(driver).move_to_element(el).perform()
您可以使用
进一步滚动 driver.execute_script("window.scrollTo(0,20)")
关于JavaScript/Selenium - 滚动到 ul 内的 li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47930289/