我想执行水平滚动,直到找到我的元素,一旦找到,我必须更新字段中的值。
period = Nov-26
ele_xpath ="//div[1]/div[@col-id='{0}']/div/span".format(period)
elem_not_found = True
y= 10 # setting initial scroll pixel size to 10
while elem_not_found:
try: driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
time.sleep(1)
driver.execute_script("window.scrollBy(2000,0)")
time.sleep(2)
ele =driver.find_element(By.XPATH,xpath)
driver.execute_script("arguments[0].scrollIntoView();", ele)
time.sleep(2)
elem_not_found = False
except:
y += 35
附件是登陆页面的屏幕截图。提前谢谢您,团队。
发现了一些东西,但它滚动不停。有人可以提供一些帮助吗?
xpath = "//div[1]/div[@col-id='{0}']/div/span".format(period)
elem_not_found = True
y = 500
while elem_not_found:
try:
SeleniumBase.driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
# ActionChains(SeleniumBase.driver).scroll_by_amount(0, y).perform()
time.sleep(1)
SeleniumBase.driver.execute_script("window.scrollBy(2000,0)")
time.sleep(1)
scroll_ele = SeleniumBase.driver.find_element(By.CSS_SELECTOR,"div.ag-body-horizontal-scroll > div.ag-body-horizontal-scroll-viewport")
actions.move_to_element(scroll_ele).send_keys(Keys.RIGHT).click().release().perform()
SeleniumBase.driver.execute_script("window.scrollBy(2000,0)",scroll_ele)
ele = SeleniumBase.driver.find_element(By.XPATH,xpath)
SeleniumBase.driver.execute_script("arguments[0].scrollIntoView();", ele)
actions.move_to_element(ele).pause(1).double_click(ele).send_keys(
Keys.CONTROL + "a").send_keys(Keys.DELETE).send_keys(str(value)).release().perform()
time.sleep(2)
allure.attach(ele,name="Element is there",attachment_type=AttachmentType.TEXT)
time.sleep(1)
elem_not_found = False
except:
y += 500