mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-04 13:07:45 +08:00
DriverElement增加set_property()方法
This commit is contained in:
parent
48894e3df7
commit
727ab0e006
@ -6,13 +6,14 @@
|
||||
"""
|
||||
import re
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
from typing import Union, List, Any, Tuple
|
||||
|
||||
from selenium.common.exceptions import TimeoutException, JavascriptException, InvalidElementStateException
|
||||
from selenium.webdriver.chrome.webdriver import WebDriver
|
||||
from selenium.webdriver.remote.webelement import WebElement
|
||||
from selenium.webdriver.support import expected_conditions as ec
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
from time import sleep
|
||||
from typing import Union, List, Any, Tuple
|
||||
|
||||
from .common import DrissionElement, str_to_loc, get_available_file_name, translate_loc, format_html
|
||||
|
||||
@ -416,7 +417,7 @@ class DriverElement(DrissionElement):
|
||||
def clear(self) -> None:
|
||||
"""清空元素文本"""
|
||||
self.run_script("arguments[0].value=''")
|
||||
# self.ele.clear()
|
||||
# self.inner_ele.clear()
|
||||
|
||||
def is_selected(self) -> bool:
|
||||
"""是否选中"""
|
||||
@ -462,12 +463,25 @@ class DriverElement(DrissionElement):
|
||||
|
||||
return img_path
|
||||
|
||||
def set_attr(self, attr: str, value: str) -> bool:
|
||||
"""设置元素属性 \n
|
||||
:param attr: 属性名
|
||||
def set_property(self, prop: str, value: str) -> bool:
|
||||
"""设置元素property属性 \n
|
||||
:param prop: 属性名
|
||||
:param value: 属性值
|
||||
:return: 是否设置成功
|
||||
"""
|
||||
try:
|
||||
value = value.replace("'", "\\'")
|
||||
self.run_script(f"arguments[0].{prop}='{value}';")
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def set_attr(self, attr: str, value: str) -> bool:
|
||||
"""设置元素attribute参数 \n
|
||||
:param attr: 参数名
|
||||
:param value: 参数值
|
||||
:return: 是否设置成功
|
||||
"""
|
||||
try:
|
||||
self.run_script(f"arguments[0].setAttribute(arguments[1], arguments[2]);", attr, value)
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user