我无法使用 python 在 Selenium 中向下滚动
I can't manage to get to scroll down in Selenium using python
我试图向下滚动页面,因为在我单击按钮一次后帮助元素与下一页按钮重叠,因为页面向下移动。
下一个按钮位于匹配历史 table 上方。
我尝试使用
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
什么都没发生,
然后我尝试使用
element=driver.find_element_by_xpath("//table[@class='Table flx-sm dir-r-sm jst-s-sm flx-nw-sm ialgn-st-sm']")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
它给我错误:MoveTargetOutOfBoundsException: Message: (1009, 835) is out of bounds of viewport width (1536) and height (750)
我尝试使用
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)
没有任何动静 still.This 是我正在尝试的代码和网站。(我也尝试使用 Chrome 但结果相同)
driver = webdriver.Firefox()
url2="https://app.senpai.gg/lol/profile/eune/Primm"
driver.get(url2)
button = driver.find_element_by_xpath('/html/body/div[2]/div/div/section/div/section/main/div[1]/div[1]/div[6]/div/div[1]/div[2]/div/button[2]')
time.sleep(10)
while true:
if(button.is_enabled() and button.is_displayed()):
button.click();
else:
break;
$('[class="el-main"]').scrollBy(0,$('[class="el-main"]').scrollHeight)
您必须找到滚动元素,然后在该元素上使用 scrolBY
driver.execute_script("$('[class=\"el-main\"]').scrollBy(0,$('[class=\"el-main\"]').scrollHeight);")
如果你得到 $ not defined 使用:
driver.execute_script("arguments[0].scrollBy(0,arguments[0].scrollHeight);", driver.find_element_by_class_name('el-main'))
您还可以这样做:
driver.get(url2)
driver.find_element_by_class_name('el-main').click()
driver.find_element_by_css_selector("body").send_keys(Keys.END)
首先你必须通过点击滚动来聚焦它,然后在正文上发送 END 键
查找定位器:
我试图向下滚动页面,因为在我单击按钮一次后帮助元素与下一页按钮重叠,因为页面向下移动。 下一个按钮位于匹配历史 table 上方。 我尝试使用
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
什么都没发生, 然后我尝试使用
element=driver.find_element_by_xpath("//table[@class='Table flx-sm dir-r-sm jst-s-sm flx-nw-sm ialgn-st-sm']")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
它给我错误:MoveTargetOutOfBoundsException: Message: (1009, 835) is out of bounds of viewport width (1536) and height (750)
我尝试使用
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)
没有任何动静 still.This 是我正在尝试的代码和网站。(我也尝试使用 Chrome 但结果相同)
driver = webdriver.Firefox()
url2="https://app.senpai.gg/lol/profile/eune/Primm"
driver.get(url2)
button = driver.find_element_by_xpath('/html/body/div[2]/div/div/section/div/section/main/div[1]/div[1]/div[6]/div/div[1]/div[2]/div/button[2]')
time.sleep(10)
while true:
if(button.is_enabled() and button.is_displayed()):
button.click();
else:
break;
$('[class="el-main"]').scrollBy(0,$('[class="el-main"]').scrollHeight)
您必须找到滚动元素,然后在该元素上使用 scrolBY
driver.execute_script("$('[class=\"el-main\"]').scrollBy(0,$('[class=\"el-main\"]').scrollHeight);")
如果你得到 $ not defined 使用:
driver.execute_script("arguments[0].scrollBy(0,arguments[0].scrollHeight);", driver.find_element_by_class_name('el-main'))
您还可以这样做:
driver.get(url2)
driver.find_element_by_class_name('el-main').click()
driver.find_element_by_css_selector("body").send_keys(Keys.END)
首先你必须通过点击滚动来聚焦它,然后在正文上发送 END 键
查找定位器: