mirror of https://github.com/jumpserver/jumpserver
perf: 支持 iframe 标签选择 (#9908)
* perf: 支持 iframe 标签选择 * perf: 完善 iframe 的选择语法 --------- Co-authored-by: Eric <xplzv@126.com>pull/10023/head
parent
bac296f82e
commit
9413fd4cd1
|
@ -18,6 +18,7 @@ class Command(Enum):
|
|||
CLICK = 'click'
|
||||
OPEN = 'open'
|
||||
CODE = 'code'
|
||||
SELECT_FRAME = 'select_frame'
|
||||
|
||||
|
||||
def _execute_type(ele: WebElement, value: str):
|
||||
|
@ -53,6 +54,9 @@ class StepAction:
|
|||
def execute(self, driver: webdriver.Chrome) -> bool:
|
||||
if not self.target:
|
||||
return True
|
||||
if self.command == 'select_frame':
|
||||
self._switch_iframe(driver, self.target)
|
||||
return True
|
||||
target_name, target_value = self.target.split("=", 1)
|
||||
by_name = self.methods_map.get(target_name.upper(), By.NAME)
|
||||
ele = driver.find_element(by=by_name, value=target_value)
|
||||
|
@ -74,6 +78,28 @@ class StepAction:
|
|||
def _execute_command_type(self, ele, value):
|
||||
ele.send_keys(value)
|
||||
|
||||
def _switch_iframe(self, driver: webdriver.Chrome, target: str):
|
||||
"""
|
||||
driver: webdriver.Chrome
|
||||
target: str
|
||||
target support three format str below:
|
||||
index=1: switch to frame by index, if index < 0, switch to default frame
|
||||
id=xxx: switch to frame by id
|
||||
name=xxx: switch to frame by name
|
||||
"""
|
||||
target_name, target_value = target.split("=", 1)
|
||||
if target_name == 'id':
|
||||
driver.switch_to.frame(target_value)
|
||||
elif target_name == 'index':
|
||||
index = int(target_value)
|
||||
if index < 0:
|
||||
driver.switch_to.default_content()
|
||||
else:
|
||||
driver.switch_to.frame(index)
|
||||
elif target_name == 'name':
|
||||
driver.switch_to.frame(target_value)
|
||||
else:
|
||||
driver.switch_to.frame(target)
|
||||
|
||||
def execute_action(driver: webdriver.Chrome, step: StepAction) -> bool:
|
||||
try:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: chrome
|
||||
display_name: Chrome Browser
|
||||
version: 0.1
|
||||
version: 0.2
|
||||
comment: Chrome Browser Open URL Page Address
|
||||
author: JumpServer Team
|
||||
exec_type: python
|
||||
|
|
Loading…
Reference in New Issue