-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplat.py
More file actions
32 lines (29 loc) · 1.09 KB
/
Copy pathtemplat.py
File metadata and controls
32 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from selenium import webdriver
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.common.by import By
class Base:
def __init__(self, driver: WebDriver):
self.driver = driver
def loctor(self, loc):
"""
定位元素的方法
:param loc: 元素定位器,例如 (By.ID, "element_id")
:return: Web 元素
"""
return self.driver.find_element(*loc)
def scroll_into_view(self, loc):
"""
滚动到元素可见
:param loc: 元素定位器
:return: None
"""
try:
element = self.loctor(loc)
if element:
print(f"Scrolling into view: {element.text if element.text else 'element with locator ' + str(loc)}") # 调试日志
self.driver.execute_script("arguments[0].scrollIntoView(true);", element)
print("Executed scrollIntoView script") # 调试日志
else:
print("Element not found") # 调试日志
except Exception as e:
print(f"Exception occurred: {e}")