mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
调整工具路径到common下;增加By类
This commit is contained in:
parent
56539b2182
commit
59d9f19cf8
@ -12,10 +12,6 @@ from .web_page import WebPage
|
|||||||
from .configs.chromium_options import ChromiumOptions
|
from .configs.chromium_options import ChromiumOptions
|
||||||
from .configs.session_options import SessionOptions
|
from .configs.session_options import SessionOptions
|
||||||
|
|
||||||
# 常用工具
|
|
||||||
from .action_chains import ActionChains
|
|
||||||
from .commons.keys import Keys
|
|
||||||
|
|
||||||
# 旧版页面类和启动配置类
|
# 旧版页面类和启动配置类
|
||||||
try:
|
try:
|
||||||
from .mixpage.mix_page import MixPage
|
from .mixpage.mix_page import MixPage
|
||||||
|
@ -7,4 +7,7 @@
|
|||||||
from FlowViewer import Listener, RequestMan
|
from FlowViewer import Listener, RequestMan
|
||||||
|
|
||||||
from .session_element import make_session_ele
|
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
|
10
DrissionPage/commons/by.py
Normal file
10
DrissionPage/commons/by.py
Normal 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'
|
@ -4,6 +4,7 @@
|
|||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
"""
|
"""
|
||||||
from re import split
|
from re import split
|
||||||
|
from .by import By
|
||||||
|
|
||||||
|
|
||||||
def get_loc(loc, translate_css=False):
|
def get_loc(loc, translate_css=False):
|
||||||
@ -219,32 +220,32 @@ def translate_loc(loc):
|
|||||||
if len(loc) != 2:
|
if len(loc) != 2:
|
||||||
raise ValueError('定位符长度必须为2。')
|
raise ValueError('定位符长度必须为2。')
|
||||||
|
|
||||||
loc_by = 'xpath'
|
loc_by = By.XPATH
|
||||||
loc_0 = loc[0].lower()
|
loc_0 = loc[0].lower()
|
||||||
|
|
||||||
if loc_0 == 'xpath':
|
if loc_0 == By.XPATH:
|
||||||
loc_str = loc[1]
|
loc_str = loc[1]
|
||||||
|
|
||||||
elif loc_0 == 'css selector':
|
elif loc_0 == By.CSS_SELECTOR:
|
||||||
loc_by = loc_0
|
loc_by = loc_0
|
||||||
loc_str = loc[1]
|
loc_str = loc[1]
|
||||||
|
|
||||||
elif loc_0 == 'id':
|
elif loc_0 == By.ID:
|
||||||
loc_str = f'//*[@id="{loc[1]}"]'
|
loc_str = f'//*[@id="{loc[1]}"]'
|
||||||
|
|
||||||
elif loc_0 == 'class name':
|
elif loc_0 == By.CLASS_NAME:
|
||||||
loc_str = f'//*[@class="{loc[1]}"]'
|
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]}"]'
|
loc_str = f'//a[text()="{loc[1]}"]'
|
||||||
|
|
||||||
elif loc_0 == 'name':
|
elif loc_0 == By.NAME:
|
||||||
loc_str = f'//*[@name="{loc[1]}"]'
|
loc_str = f'//*[@name="{loc[1]}"]'
|
||||||
|
|
||||||
elif loc_0 == 'tag name':
|
elif loc_0 == By.TAG_NAME:
|
||||||
loc_str = f'//{loc[1]}'
|
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]}")]'
|
loc_str = f'//a[contains(text(),"{loc[1]}")]'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user