Skip to main content

[TOC]

CSelenium

作者:LX

开始时间: 2021.12.15

更新时间: 2022.1.3

简化原生selenium操作,以更简短的方式对元素定位 使代码看起来更加清晰.

特点:

代码简洁,
代码具有及联操作

author: LX

Start Time: 2021.12.15

UpdateTime: 2021.12.20

Simplify native Selenium operations to locate elements in a shorter manner Make the code look cleaner.

characteristics:

Clean code,
Code has and associated operations
from src.Cselenium.CSelenium import ChromeSelenium,CSeleniumThread

def test1():
    cs = ChromeSelenium()
    cs.frame()
    # cs.get("http://www.baidu.com")
    cs.wait(2)
    cs.quit()
# test1()

def test2():
    cs = ChromeSelenium()
    cs.get("http://www.baidu.com")
    cs.id("kw").send_keys("hello")
    cs.wait(1)
    cs.quit()


def test3():
    cs = ChromeSelenium()
    cs.get("http://www.baidu.com")
    cs.id("kw").send_keys("hello world")
    cs.id("su").click()
    cs.wait(2)
    cs.quit()

# test3()

def test4():
    # 显示信息,无界面
    # info_tracking=True,is_interface=True
    cs = ChromeSelenium(info_tracking=True)
    cs.get("http://www.baidu.m")
    cs.wait(3)
    cs.id("kw").send_keys("abc")
    cs.id("su").click()
    cs.alert()
    cs.wait(4)
    cs.quit()

def test5():
    cs = ChromeSelenium()
    cs.get("http://127.0.0.1:8080/shixunyun")
    cs.implicitly_wait(3)
    cs.id("username").send_keys("lxadmin").xpath('//*[@id="app"]/div/div/form/div[3]/div/div/input').send_keys("admin")
    cs.id("loginBtn")
    cs.wait(5)
    cs.quit()


def test6():
    # 显示错误信息,并且忽略错误
    cs = ChromeSelenium(info_tracking=True,ignore_err=False)
    cs.get("http://www.baidu.com")
    cs.id("kw").send_keys([1,2,3])
    cs.wait(1)
    cs.quit()


def test7():
    # 显示错误信息,并且忽略错误
    cs = ChromeSelenium(info_tracking=True,ignore_err=False)
    cs.get("http://www.baidu.com")
    # cs.clear()
    cs.id("kw").send_keys("hello").click()
    cs.wait(1)
    cs.quit()

# test7()
# ----------------------------------CSeleniumThread测试----------------
def test8():
    # "firefox",chrome
    s = CSeleniumThread(["chrome", "firefox"], info_tracking=True)
    s.get("http://www.baidu.com")
    # s.id("kw").send_keys("hello")
    s.id("kw").send_keys("hello").wait(2).id("su").click()
    s.wait(3)
    s.quit()
    s.run()

0.0.5版本 做了一次大调整

改动时间 2022.1.3
改动一:wait_time原来int 修改为 float
改动二:ChromeSelenium类中初始化新增executable_path参数,ignore_err参数
      executable_path:浏览器驱动路径
      ignore_err:是布尔值,当值为False时,可以忽略执行方法产生当报错(大部分),一般配合
      info_tracking参数一起使用,
改动三:新增newElement()方法,这个方法可以让你去定位另一个元素
      修改原setEle()方法名为setElement(),
      新增currentTime()一个参数connector,时间的连接符号,默认-,
      新增getBrowserName()方法,返回浏览器名称,
      新增class_()方法,获取元素值class属性值,
      新增name_()方法,获取元素值name属性值,
      删除autoValue()方法,
      修改原resize()方法名为resizeWin(),
      修改原getEle()方法名为element()
      新增elements()方法,
      修改原eleIs_Displayed()方法名为isElementDisplayed(),
      修改原eleAttr()方法名g为etElementAttr(),
      修改原absElePos()方法名为elementPos(),
      修改原abaX()方法名为elementX(),
      修改原absY()方法名为elementY(),
      修改原eleSize()方法名为elementSize(),
      修改原eleWidth()方法名为elementWidth(),
      修改原eleHeight()方法名为elementHeight(),
      修改原moreWins()方法名为moreWin(),
      删除simulationKeyDown()方法,
      删除simulationKeyUp()方法,
改动四:新增CSeleniumThread类
        一种写法对映多个浏览器执行
        为了保证这个类正常运行,请将 浏览器驱动 放在与Python解释器同级目录下
        One script executes against multiple browsers
        To keep this class running, place the browser driver in the same directory as the Python interpreter
# CSeleniumThread 类例子:
from src.Cselenium.CSelenium import ChromeSelenium,CSeleniumThread
'''
    请确保chrome,firefox的驱动能正常使用
    Ensure that the Chrome and Firefox drivers work properly
'''
s = CSeleniumThread(["chrome", "firefox"], info_tracking=True)
s.get("http://www.baidu.com")
s.id("kw").send_keys("hello").wait(2).id("su").click()
s.wait(2)
s.quit()
s.run()
改动时间 2022.1.7
版本: 0.0.6
新增方法className()
新增方法classNames()
修复css()BUG
改动时间 2022.2.15
版本: 0.0.6
新增方法 location()
增加日志参数:log,保持日志需要使用pintStep()方法
改动时间 2022.3.24
版本: 0.0.7
新增类 CSeleniumThread
新增类 RandomData
修改方法 elementPos()  来源 ChromeSelenium类

Release files for CSelenium 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CSelenium 0.0.7
File Size Uploaded
CSelenium-0.0.7.tar.gz 27.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CSelenium 0.0.7
File Interpreter ABI Platform
CSelenium-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 57.2 kB

Release files / CSelenium-0.0.7.tar.gz

Download URL CSelenium-0.0.7.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4712d96d70dc70b6a78149b8769d6103adb34f1b4ddfbeaed3ad4ece78d96c49
BLAKE2b-256 checksum
How to use checksums
0519debdec99f8176eecefd59ebffd5d0221adc8f6cebda21afebd06e6d9d800
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.59.0 importlib-metadata/3.10.0 keyring/22.3.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8

Release files / CSelenium-0.0.7-py3-none-any.whl

Download URL CSelenium-0.0.7-py3-none-any.whl
Size 30.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0c00667c8b484d74e8d422e388623c6189879a8f7458c59c85a93581b83dbc0
BLAKE2b-256 checksum
How to use checksums
2c19871165356f4a0d3c147f7e6c9073a7151cf7c7e7a33c50dbbb54eadf2492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.59.0 importlib-metadata/3.10.0 keyring/22.3.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page