mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
DriverElement增加remove_attr()方法
This commit is contained in:
parent
22f28d55b4
commit
45998ec088
@ -407,10 +407,20 @@ class DriverElement(DrissionElement):
|
||||
try:
|
||||
self.run_script(f"arguments[0].{attr} = '{value}';")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
except:
|
||||
return False
|
||||
|
||||
def remove_attr(self, attr: str) -> bool:
|
||||
"""设置元素属性 \n
|
||||
:param attr: 属性名
|
||||
:return: 是否设置成功
|
||||
"""
|
||||
try:
|
||||
self.run_script(f'arguments[0].removeAttribute("{attr}");')
|
||||
return True
|
||||
except:
|
||||
raise False
|
||||
|
||||
def drag(self, x: int, y: int, speed: int = 40, shake: bool = True) -> bool:
|
||||
"""拖拽当前元素到相对位置 \n
|
||||
:param x: x变化值
|
||||
|
13
README.en.md
13
README.en.md
@ -689,6 +689,7 @@ element.clear() # Clear the element
|
||||
element.screenshot(path, filename) # Take a screenshot of the element
|
||||
element.select(text) # Select the drop- down list based on the text
|
||||
element.set_attr(attr, value) # Set element attribute value
|
||||
element.remove_attr(attr) # remove a element attribute
|
||||
element.drag(x, y, speed, shake) # Drag the relative distance of the element, you can set the speed and whether to shake randomly
|
||||
element.drag_to(ele_or_loc, speed, shake) # Drag the element to another element or a certain coordinate, you can set the speed and whether to shake randomly
|
||||
element.hover() # Hover the mouse over the element
|
||||
@ -2095,6 +2096,18 @@ Returns: bool - whether it was successful
|
||||
|
||||
|
||||
|
||||
### remove_attr()
|
||||
|
||||
Remove element attributes.
|
||||
|
||||
Parameter Description:
|
||||
|
||||
- attr: str -parameter name
|
||||
|
||||
Returns: bool - whether it was successful
|
||||
|
||||
|
||||
|
||||
### drag()
|
||||
|
||||
Drag the current element a certain distance, and return whether the drag is successful.
|
||||
|
@ -689,6 +689,7 @@ element.clear() # 清空元素
|
||||
element.screenshot(path, filename) # 对元素截图
|
||||
element.select(text) # 根据文本选择下拉列表
|
||||
element.set_attr(attr, value) # 设置元素属性值
|
||||
element.remove_attr(attr) # 删除属性
|
||||
element.drag(x, y, speed, shake) # 拖动元素相对距离,可设置速度和是否随机抖动
|
||||
element.drag_to(ele_or_loc, speed, shake) # 拖动元素到另一个元素或某个坐标,可设置速度和是否随机抖动
|
||||
element.hover() # 在元素上悬停鼠标
|
||||
@ -2075,6 +2076,18 @@ driver 模式的元素对象,包装了一个 WebElement 对象,并封装了
|
||||
|
||||
|
||||
|
||||
### remove_attr()
|
||||
|
||||
删除元素属性。
|
||||
|
||||
参数说明:
|
||||
|
||||
- attr: str - 参数名
|
||||
|
||||
返回: bool -是否成功
|
||||
|
||||
|
||||
|
||||
### drag()
|
||||
|
||||
拖拽当前元素一段距离,返回是否拖拽成功。
|
||||
|
Loading…
x
Reference in New Issue
Block a user