【发布时间】:2021-01-19 05:23:46
【问题描述】:
尝试在具有自己滚动条的框内滚动。尝试了很多方法,要么都失败了,要么不够好。
这是滚动条的html
<div id="mCSB_2_dragger_vertical" class="mCSB_dragger" style="position: absolute; min-height: 30px; display: block; height: 340px; max-height: 679.6px; top: 0px;" xpath="1"><div class="mCSB_dragger_bar" style="line-height: 30px;"></div></div>
当“顶部”值上升或下降时允许滚动。滚动条当然也会下降。一直试图模仿这一点,但无济于事
目前的一些尝试
scrollbar =driver1.find_element(By.XPATH,"//aside[@class='sidebar mCustomScrollbar _mCS_2']//div[@class='mCSB_container']")
A = ActionChains(driver1).move_to_element(scrollbar)
A.perform()
A = ActionChains(driver1)
A.perform()
W = driver1.find_element(By.CSS_SELECTOR,".visible-list > .row:nth-child(4)> .investment-item")
W.location_once_scrolled_into_view
scrollbar =driver1.find_element(By.XPATH,"//aside[@class='sidebar mCustomScrollbar _mCS_2']//div[@class='mCSB_container']").get_attribute("style")
newscrollbar = str(scrollbar).replace("top: 0px","top: -100px")
driver1.find_element(By.XPATH,"//aside[@class='sidebar mCustomScrollbar _mCS_2']//div[@class='mCSB_container']").__setattr__("style",newscrollbar)
scrollbar =driver1.find_element(By.XPATH,"//aside[@class='sidebar mCustomScrollbar _mCS_2']//div[@class='mCSB_container']").get_attribute("style")
newscrollbar = str(scrollbar).replace("top: 0px","top: -100px")
A = driver1.create_web_element(newscrollbar)
driver1.find_element(By.XPATH,"//aside[@class='sidebar mCustomScrollbar _mCS_2']//div[@class='mCSB_container']").__setattr__("style",A)
我尝试了更多方法,但无济于事..此链接提供了更多详细信息
Using scrollbar by editing attribute using Selenium Python
提前谢谢你
这里有一些方法可以看到它
A = driver1.find_element(By.XPATH,"//div[@id='mCSB_2_dragger_vertical']").get_attribute("style")
print(A) #willReturnEg:position: absolute; min-height: 30px; display: block; height: 537px; max-height: 855px; top: 0px;
Newstyle = str(A).replace("top: 0px;","top: 80px;")
driver1.__setattr__("style",Newstyle)
获取样式属性。 将其更改为字符串,例如:...top:100px...。 设置网站上的帖子属性
【问题讨论】:
标签: python html css selenium-webdriver