M17A
This commit is contained in:
parent
9a4334d5e0
commit
5865c29546
|
@ -0,0 +1,43 @@
|
|||
import os
|
||||
import time
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
|
||||
|
||||
def Browser(browser='Chrome', driver=None, binary=None, home=None):
|
||||
class WebdriverBrowser(getattr(webdriver, browser), webdriver.Firefox):
|
||||
def __init__(self, driver, binary):
|
||||
if driver:
|
||||
service = Service()
|
||||
service.path = driver
|
||||
else:
|
||||
service = None
|
||||
if binary:
|
||||
options = Options()
|
||||
options.binary_location = binary
|
||||
else:
|
||||
options = None
|
||||
super().__init__(service=service, options=options)
|
||||
|
||||
@staticmethod
|
||||
def wait(sec):
|
||||
time.sleep(sec)
|
||||
|
||||
def turn(self, url):
|
||||
return self.get(url)
|
||||
|
||||
def minimize(self):
|
||||
return self.minimize_window()
|
||||
|
||||
def maximize(self):
|
||||
return self.maximize_window()
|
||||
|
||||
def fullscreen(self):
|
||||
return self.fullscreen_window()
|
||||
|
||||
browser = WebdriverBrowser(driver=driver, binary=binary)
|
||||
browser.maximize()
|
||||
browser.implicitly_wait(10)
|
||||
home and browser.turn(home)
|
||||
return browser
|
|
@ -0,0 +1,125 @@
|
|||
import os
|
||||
import time
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
|
||||
__driver__ = webdriver.Chrome
|
||||
globals().__setitem__('__driver__', getattr(webdriver, os.environ.get('BROWSER_CHOOSE') or 'Chrome'))
|
||||
|
||||
|
||||
class Browser(__driver__):
|
||||
def __init__(self, driver=None, binary=None, home=None):
|
||||
service = Service()
|
||||
options = Options()
|
||||
if driver:
|
||||
service.path = driver
|
||||
else:
|
||||
service = None
|
||||
if binary:
|
||||
options.binary_location = binary
|
||||
else:
|
||||
options = None
|
||||
super().__init__(service=service, options=options)
|
||||
self.maximize()
|
||||
self.implicitly_wait(10)
|
||||
home and self.turn(home)
|
||||
|
||||
@staticmethod
|
||||
def wait(sec):
|
||||
"""
|
||||
强制等待,单位:秒;
|
||||
"""
|
||||
time.sleep(sec)
|
||||
|
||||
def turn(self, url=None):
|
||||
"""
|
||||
跳转新的网址;
|
||||
:param url:
|
||||
:return:
|
||||
"""
|
||||
return self.get(url)
|
||||
|
||||
def find(self, value):
|
||||
return self.find_element(By.XPATH, value)
|
||||
|
||||
def tab_create(self, url=None):
|
||||
"""
|
||||
打开新的标签页并切换至新标签页;
|
||||
"""
|
||||
self.switch_to.new_window('tab')
|
||||
isinstance(url, str) and self.turn(url)
|
||||
|
||||
def tab_close(self):
|
||||
"""
|
||||
关闭当前标签页并切换至前一个标签页;
|
||||
"""
|
||||
handles = self.window_handles
|
||||
if len(handles):
|
||||
current = handles.index(self.current_window_handle)
|
||||
self.close()
|
||||
current > 0 and self.switch_to.window(handles[current-1])
|
||||
|
||||
def tab_switch(self, tab):
|
||||
"""
|
||||
Index 按索引切换标签;
|
||||
Previous 切换上一个标签;
|
||||
Next 切换下一个标签;
|
||||
Start 切换到起始标签;
|
||||
End 切换到末尾标签;
|
||||
"""
|
||||
handles = self.window_handles
|
||||
lengths = len(handles)
|
||||
current = handles.index(self.current_window_handle)
|
||||
if isinstance(tab, int):
|
||||
handle = tab
|
||||
elif tab == 'Previous':
|
||||
handle = (current - 1)
|
||||
elif tab == 'Next':
|
||||
handle = (current + 1) % lengths
|
||||
elif tab == 'Start':
|
||||
handle = 0
|
||||
elif tab == 'End':
|
||||
handle = 0-1
|
||||
else:
|
||||
handle = None
|
||||
self.switch_to.window(handles[handle])
|
||||
self.wait(0.2)
|
||||
|
||||
def switch_to_frame(self, element):
|
||||
self.switch_to.frame(element)
|
||||
|
||||
def switch_to_parent_frame(self):
|
||||
self.switch_to.parent_frame()
|
||||
|
||||
def switch_to_default(self):
|
||||
self.switch_to.default_content()
|
||||
|
||||
def action_chains(self):
|
||||
actions = ActionChains(self)
|
||||
return actions
|
||||
|
||||
def minimize(self):
|
||||
"""
|
||||
浏览器窗口最小化;
|
||||
"""
|
||||
return self.minimize_window()
|
||||
|
||||
def maximize(self):
|
||||
"""
|
||||
浏览器窗口最大化;
|
||||
"""
|
||||
return self.maximize_window()
|
||||
|
||||
def fullscreen(self):
|
||||
"""
|
||||
浏览器进入全屏模式,注意:可能会因为新页面跳转导致全屏模式退出,并且浏览器窗口大小可能会被重设;
|
||||
"""
|
||||
return self.fullscreen_window()
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from Base.Class.Http import *
|
||||
import os, sys
|
||||
|
||||
|
||||
print(Session().http(method='GET', url='https://www.fanscloud.net/iplookup')['text'])
|
||||
lst = [1, 2, 3]
|
||||
print(lst[0-1])
|
|
@ -1,40 +1,3 @@
|
|||
# import re
|
||||
# from Base.Class.Encrypt import *
|
||||
#
|
||||
# def _sub_variable(text, vars_dict):
|
||||
# if not isinstance(text, str):
|
||||
# return text
|
||||
# for variable_name in re.findall('\${(.*?)}', text):
|
||||
# try:
|
||||
# value = vars_dict[variable_name]
|
||||
# except Exception:
|
||||
# value = ''
|
||||
# if value is None:
|
||||
# value = ''
|
||||
# text = text.replace('${%s}' % variable_name, str(value))
|
||||
# return text
|
||||
#
|
||||
# def _sub_encry(text, encr_dict):
|
||||
# if not isinstance(text, str):
|
||||
# return text
|
||||
# for encr_text in re.findall('\$([0-9a-zA-Z_]+)\((.*?)\)', text):
|
||||
# try:
|
||||
# value = encr_dict[encr_text[0]](encr_text[1])
|
||||
# except Exception:
|
||||
# value = ''
|
||||
# if value is None:
|
||||
# value = ''
|
||||
# text = text.replace('$%s(%s)' % (encr_text[0], encr_text[1]), str(value))
|
||||
# return text
|
||||
#
|
||||
# # print(_sub_variable(text='name=${name}', vars_dict={'name': '赵亚凡163'}))
|
||||
# print(_sub_encry(text='name=$md5(赵亚凡163)', encr_dict={'md5': md5}))
|
||||
import time
|
||||
|
||||
# def read_encoding(path):
|
||||
# import chardet
|
||||
# return chardet.detect(open(path, 'rb').read(4096))['encoding']
|
||||
#
|
||||
# print(read_encoding('D:\\Desktop\\1.csv'))
|
||||
|
||||
|
||||
print({'是': True, '否': False}['是'])
|
||||
print(time.sleep(1))
|
|
@ -0,0 +1,27 @@
|
|||
# import time
|
||||
# from selenium import webdriver
|
||||
# from selenium.webdriver.chrome.options import Options
|
||||
# from selenium.webdriver.chrome.service import Service
|
||||
#
|
||||
# service = Service()
|
||||
# service.path = 'chromedriver.exe'
|
||||
# options = Options()
|
||||
# options.binary_location = 'C:/Users/zhaoyafan/AppData/Local/360Chrome/Chrome/Application/360chrome.exe'
|
||||
# browser = webdriver.Chrome(service=service, options=options)
|
||||
#
|
||||
# browser.maximize_window()
|
||||
#
|
||||
# browser.implicitly_wait(10)
|
||||
# browser.get("https://www.fanscloud.net/")
|
||||
# browser.fullscreen_window()
|
||||
# browser.minimize_window()
|
||||
|
||||
from Base.Class.Browser import *
|
||||
|
||||
|
||||
browser = Browser(browser='Chrome', driver='chromedriver', binary='C:/Users/zhaoyafan/AppData/Local/360Chrome/Chrome/Application/360chrome.exe')
|
||||
browser.turn('https://github.com/signup?user_email=&source=form-home-signup')
|
||||
browser.wait(5)
|
||||
browser.turn('https://www.fanscloud.net/')
|
||||
browser.wait(5)
|
||||
browser.quit()
|
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
|
||||
os.environ['BROWSER_CHOOSE'] = 'Chrome'
|
||||
from Base.Class.Browser2 import *
|
||||
|
||||
|
||||
# browser = Browser(driver='chromedriver', binary='C:/Users/zhaoyafan/AppData/Local/360Chrome/Chrome/Application/360chrome.exe')
|
||||
browser = Browser(driver='chromedriver_102')
|
||||
browser.turn('http://124.221.234.187/fanwe/')
|
||||
|
||||
# el = browser.find_element(By.PARTIAL_LINK_TEXT, '首页')
|
||||
# browser.action_chains().move_to_element(el).pause(3).click_and_hold(el).pause(1).release(el).perform()
|
||||
# browser.wait(3)
|
||||
browser.action_chains().click(browser.find('//input[@id="Iajax-login-submit"]')).perform()
|
||||
|
||||
|
||||
browser.wait(5)
|
||||
browser.quit()
|
Loading…
Reference in New Issue