问题
This is an addition to the first version of the question i asked since i still can not solve it so more details are in here Selenium scroll into view with a twist Python
I have managed to collect the attribute ..but have no idea how to edit it to work in the way i want..i want to be able to just simply scroll down i have tried multiple different ways to acheive this but none of them seem to work
Here is the code of the countless ways i have tried to figure this out.
scrollbar = str(driver1.find_element_by_xpath("//div[@id='mCSB_2_dragger_vertical']").get_attribute("style"))
print(scrollbar)
driver1.execute_script("document.getElementByXPath('lga').style.top = '200px';")
scrollbar = str(driver1.find_element_by_xpath("//div[@id='mCSB_2_dragger_vertical']").get_attribute("style"))
print(scrollbar)
# new_style = driver1.find_element_by_xpath("//div[@id='mCSB_2_dragger_vertical']").get_attribute("style").replace('top: 0px', 'top: 300px')
# driver1.execute_script('arguments[6].setAttribute("style", "%s")' %new_style, scrollbar)
# print(scrollbar)
# element = driver1.find_element_by_xpath("//div[@id='mCSB_2_dragger_vertical']")
# A = driver1.execute_script("argument[0]",element)
# A =driver1.execute_script("arguments[0].value = 'top: 100px'", element)
# print(A)
# driver1.execute_script("arguments[0].setAttribute('top:', 'top: 300px')", element)
# div_elem = driver1.find_element_by_xpath("//div[@id='mCSB_2_dragger_vertical']")
# print(div_elem.text)
# new_style = div_elem.get_attribute('style').replace('top: 0px', 'top: 300px')
# driver1.execute_script('arguments[0].setAttribute("style", "%s")' % new_style, div_elem)
# print(div_elem.text)
# newvalue = "-300px"
# splitting = scrollbar.split(": ")
# indextochange = str(splitting[6])
# EntirenewAttribute = str(scrollbar.replace(indextochange,newvalue))
# driver1.execute(scrollbar.replace(scrollbar,EntirenewAttribute))#EntirenewAttribute
The first print line correctly returns the data i want to change
position: absolute; min-height: 30px; display: block; height: 229px; max-height: 675px; top: 0px;
When using the scrollbar the "top"value changes ...hence i was trying to automatically change it.but to no avail.
来源:https://stackoverflow.com/questions/63588178/using-scrollbar-by-editing-attribute-using-selenium-python