python selenium 操作浏览器汇总

logging模块封装
import logging
import os

”’
logging.debug(‘debug级别,一般用来打印一些调试信息,级别*低’)
logging.info(‘info级别,一般用来打印一些正常的操作信息’)
logging.warning(‘waring级别,一般用来打印警告信息’)
logging.error(‘error级别,一般用来打印一些错误信息’)
logging.critical(‘critical级别,一般用来打印一些致命的错误信息,等级*高’)
”’

class MyLog:

def __init__(self):
logging.basicConfig(level=logging.INFO, # 控制台打印的日志级别
filename=os.getcwd() + ‘/log/test.log’,
filemode=’a’, # 模式,有w和a,w就是写模式,每次都会重新写日志,覆盖之前的日志
# a是追加模式,默认如果不写的话,就是追加模式
format=
‘%(asctime)s – %(pathname)s[line:%(lineno)d] – %(levelname)s: %(message)s’
# 日志格式
)
self.my_log = logging.getLogger(‘test’)

def error_log(self, value):
self.my_log.error(value)

def warning_log(self, value):
self.my_log.warning(value)

def info_log(self, value):
self.my_log.info(value)

def debug_log(self, value):
self.my_log.debug(value)

def critical_log(self, value):
self.my_log.critical(value)

selenium 动作封装
import configparser
import time
import pyautogui
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.wait import WebDriverWait
from module.log import *
from selenium.webdriver.support.select import Select

my_log = MyLog()
conf = configparser.ConfigParser()
conf.read(os.getcwd() + ‘/config/config.ini’, encoding=’utf-8′)

class BrowserAction:

# 初始化
def __init__(self):
try:
my_log.info_log(“————————-测试开始————————-“)
print(“————————-测试开始————————-“)
# 是否开启浏览器被控提示
browser_autotest_tip = conf.get(‘browser’, ‘browser_autotest_tip’)
# 是否开启无痕模式
browser_stealth = conf.get(‘browser’, ‘browser_stealth’)
# 是否禁用javascript
browser_javascript = conf.get(‘browser’, ‘browser_javascript’)
# 是否加载图片
browser_image = conf.get(‘browser’, ‘browser_image’)
# 是否显示浏览器窗口,不显示窗口可能会导致某些动作失败
browser_show = conf.get(‘browser’, ‘browser_show’)
# 是否显示滚动条
browser_scrollbar = conf.get(‘browser’, ‘browser_scrollbar’)
# 是否启动浏览器*大化
browser_maximized = conf.get(‘browser’, ‘browser_maximized’)
# 隐等待时间
implicitly_wait = conf.get(‘browser’, ‘implicitly_wait’)
# self.implicitlyWait = 10
# 实例化浏览器设置
self.options = webdriver.ChromeOptions()
# 启动时设置默认语言为中文 UTF-8
self.options.add_argument(‘lang=zh_CN.UTF-8’)
# 设置浏览器默认下载路径
self.all_url = os.getcwd() + “/download”
self.prefs = {‘profile.default_content_settings.popups’: 0,
‘download.default_directory’: ‘%s’ % self.all_url}
self.options.add_experimental_option(‘prefs’, self.prefs)
# 其他浏览器配置
if browser_autotest_tip == ‘True’:
self.options.add_experimental_option(
“excludeSwitches”, [‘enable-automation’]) # 禁用浏览器正在被自动化程序控制的提示
# self.options.add_argument(‘–disable-infobars’) # 禁止策略化
# 解决DevToolsActivePort文件不存在的报错
self.options.add_argument(‘–no-sandbox’)
# self.options.add_argument(‘window-size=1920×3000’) # 指定浏览器分辨率
self.options.add_argument(‘–disable-gpu’) # 谷歌文档提到需要加上这个属性来规避bug
if browser_stealth == ‘True’:
self.options.add_argument(‘–incognito’) # 隐身模式(无痕模式)
if browser_javascript == ‘True’:
self.options.add_argument(
‘–disable-javascript’) # 禁用javascript
if browser_maximized == ‘True’:
# *大化运行(全屏窗口),不设置,取元素会报错
self.options.add_argument(‘–start-maximized’)
# self.options.add_argument(‘–disable-infobars’) # 禁用浏览器正在被自动化程序控制的提示
if browser_scrollbar == ‘True’:
self.options.add_argument(
‘–hide-scrollbars’) # 隐藏滚动条, 应对一些特殊页面
if browser_image == ‘True’:
self.options.add_argument(
‘blink-settings=imagesEnabled=false’) # 不加载图片, 提升速度
if browser_show == ‘True’:
# 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
self.options.add_argument(‘–headless’)

# 驱动谷歌浏览器
self.driver = webdriver.Chrome(executable_path=os.getcwd() + ‘/driver/chromedriver.exe’,
chrome_options=self.options)
self.driver.implicitly_wait(implicitly_wait)
except Exception as e:
my_log.error_log(e)
print(e)

# 打开网页
def open_url(self, url):
try:
self.driver.get(url)
my_log.info_log(“打开地址:%s” % url)
print(“打开地址:%s” % url)
except Exception as e:
my_log.error_log(e)
print(e)

# 鼠标点击
def element_click(self, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
self.driver.find_element_by_id(elementId).click()
my_log.info_log(“鼠标点击元素id:%s” % elementId)
print(“鼠标点击元素id:%s” % elementId)
elif elementName is not None:
self.driver.find_element_by_name(elementName).click()
my_log.info_log(“鼠标点击元素name:%s” % elementName)
print(“鼠标点击元素name:%s” % elementName)
elif elementXpath is not None:
self.driver.find_element_by_xpath(elementXpath).click()
my_log.info_log(“鼠标点击元素xpath:%s” % elementXpath)
print(“鼠标点击元素xpath:%s” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 键盘输入
def input_value(self, value=None, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
element = self.driver.find_element_by_id(elementId)
element.clear()
element.clear()
element.clear()
element.send_keys(value)
my_log.info_log(“元素id:%s,输入:%s” % (elementId, value))
print(“元素id:%s,输入:%s” % (elementId, value))
elif elementName is not None:
element = self.driver.find_element_by_name(elementName)
element.clear()
element.clear()
element.clear()
element.send_keys(value)
my_log.info_log(“元素name:%s,输入:%s” % (elementName, value))
print(“元素name:%s,输入:%s” % (elementName, value))
elif elementXpath is not None:
element = self.driver.find_element_by_xpath(elementXpath)
element.clear()
element.clear()
element.clear()
element.send_keys(value)
my_log.info_log(“元素xpath:%s,输入:%s” % (elementXpath, value))
print(“元素xpath:%s,输入:%s” % (elementXpath, value))
except Exception as e:
my_log.error_log(e)
print(e)

# 清空输入框
def element_clear(self, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
element = self.driver.find_element_by_id(elementId)
element.clear()
element.clear()
my_log.info_log(“清空元素id:%s” % elementId)
print(“清空元素id:%s” % elementId)
elif elementName is not None:
element = self.driver.find_element_by_name(elementName)
element.clear()
element.clear()
my_log.info_log(“清空元素name:%s” % elementName)
print(“清空元素name:%s” % elementName)
elif elementXpath is not None:
element = self.driver.find_element_by_xpath(elementXpath)
element.clear()
element.clear()
my_log.info_log(“清空元素xpath:%s” % elementXpath)
print(“清空元素xpath:%s” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 鼠标双击
def element_double_click(self, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
self.driver.find_element_by_id(elementId).double_click()
my_log.info_log(“鼠标双击元素id:%s” % elementId)
print(“鼠标双击元素id:%s” % elementId)
elif elementName is not None:
self.driver.find_element_by_name(elementName).double_click()
my_log.info_log(“鼠标双击元素name:%s” % elementName)
print(“鼠标双击元素name:%s” % elementName)
elif elementXpath is not None:
self.driver.find_element_by_xpath(elementXpath).double_click()
my_log.info_log(“鼠标双击元素xpath:%s” % elementXpath)
print(“鼠标双击元素xpath:%s” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 浏览器前进
def browser_forward(self):
try:
self.driver.forward()
my_log.info_log(“浏览器前进”)
print(“浏览器前进”)
except Exception as e:
my_log.error_log(e)
print(e)

# 浏览器后退
def browser_back(self):
try:
self.driver.back()
my_log.info_log(“浏览器后退”)
print(“浏览器后退”)
except Exception as e:
my_log.error_log(e)
print(e)

# 浏览器*大化
def browser_maxsize(self):
try:
self.driver.maximize_window()
my_log.info_log(“浏览器*大化”)
print(“浏览器*大化”)
except Exception as e:
my_log.error_log(e)
print(e)

# 滚动到元素位置并点击
def go_to_element_click(self, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
ele = self.driver.find_element_by_id(elementId)
self.driver.execute_script(“arguments[0].click();”, ele)
my_log.info_log(“滚动到元素id:%s,并点击” % elementId)
print(“滚动到元素id:%s,并点击” % elementId)
elif elementName is not None:
ele = self.driver.find_element_by_name(elementName)
self.driver.execute_script(“arguments[0].click();”, ele)
my_log.info_log(“滚动到元素name:%s,并点击” % elementName)
print(“滚动到元素name:%s,并点击” % elementName)
elif elementXpath is not None:
ele = self.driver.find_element_by_xpath(elementXpath)
self.driver.execute_script(“arguments[0].click();”, ele)
my_log.info_log(“滚动到元素xpath:%s,并点击” % elementXpath)
print(“滚动到元素xpath:%s,并点击” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 鼠标右击
def element_right_click(self, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
self.driver.find_element_by_id(elementId).context_click()
my_log.info_log(“鼠标双击元素id:%s” % elementId)
print(“鼠标双击元素id:%s” % elementId)
elif elementName is not None:
self.driver.find_element_by_name(elementName).context_click()
my_log.info_log(“鼠标双击元素name:%s” % elementName)
print(“鼠标双击元素name:%s” % elementName)
elif elementXpath is not None:
self.driver.find_element_by_xpath(elementXpath).context_click()
my_log.info_log(“鼠标双击元素xpath:%s” % elementXpath)
print(“鼠标双击元素xpath:%s” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 鼠标移动到元素上
def mouse_move_to_element(self, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
move = self.driver.find_element_by_id(elementId)
ActionChains(self.driver).move_to_element(move).perform()
ActionChains(self.driver).move_to_element(move).perform()
ActionChains(self.driver).move_to_element(move).perform()
my_log.info_log(“鼠标移动到元素id:%s” % elementId)
print(“鼠标移动到元素id:%s” % elementId)
elif elementName is not None:
move = self.driver.find_element_by_name(elementName)
ActionChains(self.driver).move_to_element(move).perform()
ActionChains(self.driver).move_to_element(move).perform()
ActionChains(self.driver).move_to_element(move).perform()
my_log.info_log(“鼠标移动到元素name:%s” % elementName)
print(“鼠标移动到元素name:%s” % elementName)
elif elementXpath is not None:
move = self.driver.find_element_by_xpath(elementXpath)
ActionChains(self.driver).move_to_element(move).perform()
ActionChains(self.driver).move_to_element(move).perform()
ActionChains(self.driver).move_to_element(move).perform()
my_log.info_log(“鼠标移动到元素xpath:%s” % elementXpath)
print(“鼠标移动到元素xpath:%s” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 拖动元素到另一元素上
def drag_element_to_element(self, startElementId=None, endElementId=None,
startElementName=None, endElementName=None,
startElementXpath=None, endElementXpath=None):
try:
start = None
end = None
if startElementId is not None:
start = self.driver.find_element_by_id(startElementId)
elif startElementName is not None:
start = self.driver.find_element_by_name(startElementName)
elif startElementXpath is not None:
start = self.driver.find_element_by_xpath(startElementXpath)
if endElementId is not None:
end = self.driver.find_element_by_id(endElementId)
elif endElementName is not None:
end = self.driver.find_element_by_name(endElementName)
elif endElementXpath is not None:
end = self.driver.find_element_by_xpath(endElementXpath)
ActionChains(self.driver).drag_and_drop(start, end).perform()
my_log.info_log(“将元素 %s 拖动到元素 %s” % (start, end))
print(“将元素 %s 拖动到元素 %s” % (start, end))
except Exception as e:
my_log.error_log(e)
print(e)

# 强制等待
def time_sleep(self, num):
time.sleep(num)
my_log.info_log(“强制等待%s秒” % num)
print(“强制等待%s秒” % num)

# 等待某个元素出现
def wait_element_exist(self, wait_time, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
WebDriverWait(self.driver, wait_time).until(
self.driver.find_element_by_id(elementId))
my_log.info_log(“等待元素出现:%s” % elementId)
print(“等待元素出现:%s” % elementId)
elif elementName is not None:
WebDriverWait(self.driver, wait_time).until(
self.driver.find_element_by_name(elementName))
my_log.info_log(“等待元素出现:%s” % elementName)
print(“等待元素出现:%s” % elementName)
elif elementXpath is not None:
WebDriverWait(self.driver, wait_time).until(
self.driver.find_element_by_xpath(elementXpath))
my_log.info_log(“等待元素出现:%s” % elementXpath)
print(“等待元素出现:%s” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 刷新页面
def browser_refresh(self):
try:
self.driver.refresh()
my_log.info_log(“刷新页面”)
print(“刷新页面”)
except Exception as e:
my_log.error_log(e)
print(e)

# 切换标签页
def switch_browser_tab(self, num):
try:
all_handles = self.driver.window_handles
self.driver.switch_to.window(all_handles[num – 1])
my_log.info_log(“切换到标签页%s” % num)
print(“切换到标签页%s” % num)
except Exception as e:
my_log.error_log(e)
print(e)

# 滚动条上下移动
def scroll_bar_move(self, num):
try:
self.driver.execute_script(“window.scrollBy(0, %d)” % num)
my_log.info_log(“滚动条移动:%s” % num)
print(“滚动条移动:%s” % num)
except Exception as e:
my_log.error_log(e)
print(e)

# 关闭当前标签页
def close_current_tab(self):
try:
self.driver.close()
my_log.info_log(“关闭当前标签页”)
print(“关闭当前标签页”)
except Exception as e:
my_log.error_log(e)
print(e)

# 关闭浏览器
def close_browser(self):
try:
self.driver.quit()
my_log.info_log(“关闭浏览器”)
print(“关闭浏览器”)
my_log.info_log(“————————-测试结束————————-“)
print(“————————-测试结束————————-“)
except Exception as e:
my_log.error_log(e)
print(e)

# 屏幕截图
def screen_shot(self, name):
try:
current_time = time.strftime(
‘%Y%m%d%H%M%S’, time.localtime(time.time()))
self.driver.get_screenshot_as_file(
“images/” + name + ‘_’ + current_time + “.png”)
my_log.info_log(“保存屏幕截图成功”)
print(“保存屏幕截图成功”)
except Exception as e:
my_log.error_log(e)
print(e)

# 元素截图
def element_screen_shot(self, elementId=None, elementName=None, elementXpath=None):
try:
current_time = time.strftime(
‘%Y%m%d%H%M%S’, time.localtime(time.time()))
if elementId is not None:
element = self.driver.find_element_by_id(elementId)
element.screenshot(‘images/元素截图_’ + current_time + “.png”)
elif elementName is not None:
element = self.driver.find_element_by_name(elementName)
element.screenshot(‘images/元素截图_’ + current_time + “.png”)
elif elementXpath is not None:
element = self.driver.find_element_by_xpath(elementXpath)
element.screenshot(‘images/元素截图_’ + current_time + “.png”)
my_log.info_log(“保存元素截图成功”)
print(“保存元素截图成功”)
except Exception as e:
my_log.error_log(e)
print(e)

# 点击坐标点
def point_click(self, x, y):
try:
pyautogui.click(x, y)
my_log.info_log(“鼠标点击屏幕坐标点:%s,%s” % (x, y))
print(“鼠标点击屏幕坐标点:%s,%s” % (x, y))
except Exception as e:
my_log.error_log(e)
print(e)

# 鼠标双击坐标点
def point_double_click(self, x, y):
try:
pyautogui.click(x, y, clicks=2)
my_log.info_log(“鼠标双击屏幕坐标点:%s,%s” % (x, y))
print(“鼠标双击屏幕坐标点:%s,%s” % (x, y))
except Exception as e:
my_log.error_log(e)
print(e)

# 键盘输入
def keyboard_click(self, button):
try:
pyautogui.press(button)
my_log.info_log(“按下键盘:%s” % button)
print(“按下键盘:%s” % button)
except Exception as e:
my_log.error_log(e)
print(e)

# 组合键
def hot_key(self, key1, key2):
try:
pyautogui.hotkey(key1, key2)
my_log.info_log(“按下键盘:%s + %s” % (key1, key2))
print(“按下键盘:%s + %s” % (key1, key2))
except Exception as e:
my_log.error_log(e)
print(e)

# 获取当前页面标题
def get_current_page_title(self):
try:
my_log.info_log(“获取当前页面标题为:%s” % self.driver.title)
print(“获取当前页面标题为:%s” % self.driver.title)
return self.driver.title
except Exception as e:
my_log.error_log(e)
print(e)

# 获取元素某个属性的值
def get_element_attributes(self, attributes, elementId=None, elementName=None, elementXpath=None):
try:
value = None
if elementId is not None:
value = self.driver.find_element_by_id(
elementId).get_attribute(attributes)
my_log.info_log(“获取元素 %s 属性 %s 值为: %s” % (elementId, attributes, value))
print(“获取元素 %s 属性 %s 值为: %s” % (elementId, attributes, value))
elif elementName is not None:
value = self.driver.find_element_by_name(
elementName).get_attribute(attributes)
my_log.info_log(“获取元素 %s 属性 %s 值为: %s” % (elementName, attributes, value))
print(“获取元素 %s 属性 %s 值为: %s” % (elementName, attributes, value))
elif elementXpath is not None:
value = self.driver.find_element_by_xpath(
elementXpath).get_attribute(attributes)
my_log.info_log(“获取元素 %s 属性 %s 值为: %s” % (elementXpath, attributes, value))
print(“获取元素 %s 属性 %s 值为: %s” % (elementXpath, attributes, value))
return value
except Exception as e:
my_log.error_log(e)
print(e)

# 获取元素文本
def get_element_text(self, elementId=None, elementName=None, elementXpath=None):
try:
value = None
if elementId is not None:
value = self.driver.find_element_by_id(elementId).text
my_log.info_log(“获取元素 %s 文本为: %s” % (elementId, value))
print(“获取元素 %s 文本为: %s” % (elementId, value))
elif elementName is not None:
value = self.driver.find_element_by_name(elementName).text
my_log.info_log(“获取元素 %s 文本为: %s” % (elementName, value))
print(“获取元素 %s 文本为: %s” % (elementName, value))
elif elementXpath is not None:
value = self.driver.find_element_by_xpath(elementXpath).text
my_log.info_log(“获取元素 %s 文本为: %s” % (elementXpath, value))
print(“获取元素 %s 文本为: %s” % (elementXpath, value))
return value
except Exception as e:
my_log.error_log(e)
print(e)

# 判断元素存在
def find_element(self, elementId=None, elementName=None, elementXpath=None):
try:
result = None
if elementId is not None:
try:
self.driver.find_element_by_id(elementId)
result = True
except:
result = False
my_log.info_log(“判断元素 %s 是否存在: %s” % (elementId, result))
print(“判断元素 %s 是否存在: %s” % (elementId, result))
elif elementId is not None:
try:
self.driver.find_element_by_name(elementName)
result = True
except:
result = False
my_log.info_log(“判断元素 %s 是否存在: %s” % (elementName, result))
print(“判断元素 %s 是否存在: %s” % (elementName, result))
elif elementId is not None:
try:
self.driver.find_element_by_xpath(elementXpath)
result = True
except:
result = False
my_log.info_log(“判断元素 %s 是否存在: %s” % (elementXpath, result))
print(“判断元素 %s 是否存在: %s” % (elementXpath, result))
return result
except Exception as e:
my_log.error_log(e)
print(e)

# 浏览器弹窗确定
def alert_click(self):
try:
alert = self.driver.switch_to.alert
alert.accept()
my_log.info_log(“点击浏览器弹框确定按钮”)
print(“点击浏览器弹框确定按钮”)
except Exception as e:
my_log.error_log(e)
print(e)

# 浏览器弹窗取消
def alert_close(self):
try:
alert = self.driver.switch_to.alert
alert.dismiss()
my_log.info_log(“点击浏览器弹框取消按钮”)
print(“点击浏览器弹框取消按钮”)
except Exception as e:
my_log.error_log(e)
print(e)

# 浏览器弹窗输入
def alert_input(self, key):
try:
prompt = Alert(self.driver)
prompt.send_keys(key)
my_log.info_log(“浏览器弹框输入:%s” % key)
print(“浏览器弹框输入:%s” % key)
except Exception as e:
my_log.error_log(e)
print(e)

# 获取浏览器弹窗内容
def get_alert_text(self):
try:
my_log.info_log(“获取浏览器弹窗内容:%s” % self.driver.switch_to.alert.text)
print(“获取浏览器弹窗内容:%s” % self.driver.switch_to.alert.text)
return self.driver.switch_to.alert.text
except Exception as e:
my_log.error_log(e)
print(e)

# 进入iframe
def enter_iframe(self, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
self.driver.switch_to.frame(
self.driver.find_element_by_id(elementId))
my_log.info_log(“进入iframe:%s” % elementId)
print(“进入iframe:%s” % elementId)
elif elementName is not None:
self.driver.switch_to.frame(
self.driver.find_element_by_name(elementName))
my_log.info_log(“进入iframe:%s” % elementName)
print(“进入iframe:%s” % elementName)
elif elementXpath is not None:
self.driver.switch_to.frame(
self.driver.find_element_by_xpath(elementXpath))
my_log.info_log(“进入iframe:%s” % elementXpath)
print(“进入iframe:%s” % elementXpath)
except Exception as e:
my_log.error_log(e)
print(e)

# 跳出iframe
def out_iframe(self):
try:
self.driver.switch_to.parent_frame()
my_log.info_log(“跳出iframe”)
print(“跳出iframe”)
except Exception as e:
my_log.error_log(e)
print(e)

# 判断元素是否可用
def element_is_enabled(self, elementId=None, elementName=None, elementXpath=None):
try:
element = None
if elementId is not None:
element = self.driver.find_element_by_id(elementId)
elif elementName is not None:
element = self.driver.find_element_by_name(elementName)
elif elementXpath is not None:
element = self.driver.find_element_by_xpath(elementXpath)
my_log.info_log(“判断元素是否可用:%s” % element.is_enabled())
print(“判断元素是否可用:%s” % element.is_enabled())
return element.is_enabled()
except Exception as e:
my_log.error_log(e)
print(e)

# 选择下拉列表选项
def select_list(self, text, elementId=None, elementName=None, elementXpath=None):
try:
if elementId is not None:
opt = self.driver.find_element_by_id(elementId)
Select(opt).select_by_visible_text(text)
my_log.info_log(“选择下拉列表选项:%s” % text)
print(“选择下拉列表选项:%s” % text)
elif elementName is not None:
opt = self.driver.find_element_by_name(elementName)
Select(opt).select_by_visible_text(text)
my_log.info_log(“选择下拉列表选项:%s” % text)
print(“选择下拉列表选项:%s” % text)
elif elementXpath is not None:
opt = self.driver.find_element_by_xpath(elementXpath)
Select(opt).select_by_visible_text(text)
my_log.info_log(“选择下拉列表选项:%s” % text)
print(“选择下拉列表选项:%s” % text)
except Exception as e:
my_log.error_log(e)
print(e)

# 执行js代码
def excute_script(self, jscode):
try:
self.driver.execute_script(jscode)
my_log.info_log(“执行javascript代码: %s” % jscode)
print(“执行javascript代码: %s” % jscode)
except Exception as e:
my_log.error_log(e)
print(e)