[python 选中代码按键盘tab键向后缩进一个缩进单位,按shitt+tab向前回退一个缩进单位]
Selenium元素定位封装
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from project.job.src.Common.GeneralMethord.generalfunction import generalfunction
class weboperation:
# 实现方法按照制定的相对路径保存截图
def get_web_picture(self, browser, relatively_path):
gf = generalfunction()
picture_path = gf.get_dir_by_abspath(relatively_path)
picture_file = picture_path + "\\"+gf.get_shijianchuo()+".png"
sleep(2)
browser.get_screenshot_as_file(picture_file)
# 实现方法按照超链接文字点击
def click_element_by_link_text(self, browser, *args):
waiter = WebDriverWait(browser,10)
for ele in args:
waiter.until(ec.presence_of_element_located((By.LINK_TEXT, ele))).click()
# 实现方法动态定位单个元素
def find_element_by_webdriverwait(self, browser, *args):
waiter = WebDriverWait(browser, 10)
element = waiter.until(ec.presence_of_element_located(*args))
return element
# 定义方法实现动态点击
def click_element_by_webdriverwait(self, browser, *args):
self.find_element_by_webdriverwait(browser, *args).click()
#定义方法实现动态添加数据
def send_keys_by_webdriverwait(self, browser,values, *args):
self.find_element_by_webdriverwait(browser, *args).send_keys(values)
# 实现方法动态判断元素可否点击,可点击返回element
def judging_element_click_by_webdriverwait(self, browser, *args):
waiter = WebDriverWait(browser, 10)
element = waiter.until(ec.element_to_be_clickable(*args))
return element
#实现方法动态判断网页标题是否为某个字符串
def judging_title_is(self, browser, title):
waiter = WebDriverWait(browser, 10)
result = waiter.until(ec.title_is(title))
return result
#实现方法动态判断网页标题是否包含某个字符串
def judging_title_contains(self, browser, title):
waiter = WebDriverWait(browser, 10)
result = waiter.until(ec.title_contains(title))
return result
#