调整工具路径到common下;增加By类

This commit is contained in:
g1879 2023-03-01 17:35:22 +08:00
parent 56539b2182
commit 59d9f19cf8
4 changed files with 25 additions and 15 deletions

View File

@ -12,10 +12,6 @@ from .web_page import WebPage
from .configs.chromium_options import ChromiumOptions
from .configs.session_options import SessionOptions
# 常用工具
from .action_chains import ActionChains
from .commons.keys import Keys
# 旧版页面类和启动配置类
try:
from .mixpage.mix_page import MixPage

View File

@ -7,4 +7,7 @@
from FlowViewer import Listener, RequestMan
from .session_element import make_session_ele
from .easy_set import get_match_driver
from .action_chains import ActionChains
from .commons.keys import Keys
from .commons.by import By

View File

@ -0,0 +1,10 @@
# -*- coding:utf-8 -*-
class By:
ID = 'id'
XPATH = 'xpath'
LINK_TEXT = 'link text'
PARTIAL_LINK_TEXT = 'partial link text'
NAME = 'name'
TAG_NAME = 'tag name'
CLASS_NAME = 'class name'
CSS_SELECTOR = 'css selector'

View File

@ -4,6 +4,7 @@
@Contact : g1879@qq.com
"""
from re import split
from .by import By
def get_loc(loc, translate_css=False):
@ -219,32 +220,32 @@ def translate_loc(loc):
if len(loc) != 2:
raise ValueError('定位符长度必须为2。')
loc_by = 'xpath'
loc_by = By.XPATH
loc_0 = loc[0].lower()
if loc_0 == 'xpath':
if loc_0 == By.XPATH:
loc_str = loc[1]
elif loc_0 == 'css selector':
elif loc_0 == By.CSS_SELECTOR:
loc_by = loc_0
loc_str = loc[1]
elif loc_0 == 'id':
elif loc_0 == By.ID:
loc_str = f'//*[@id="{loc[1]}"]'
elif loc_0 == 'class name':
elif loc_0 == By.CLASS_NAME:
loc_str = f'//*[@class="{loc[1]}"]'
elif loc_0 == 'link text':
elif loc_0 == By.PARTIAL_LINK_TEXT:
loc_str = f'//a[text()="{loc[1]}"]'
elif loc_0 == 'name':
elif loc_0 == By.NAME:
loc_str = f'//*[@name="{loc[1]}"]'
elif loc_0 == 'tag name':
loc_str = f'//{loc[1]}'
elif loc_0 == By.TAG_NAME:
loc_str = f'//*[name()="{loc[1]}"]'
elif loc_0 == 'partial link text':
elif loc_0 == By.PARTIAL_LINK_TEXT:
loc_str = f'//a[contains(text(),"{loc[1]}")]'
else: