Comments (3)
LP 需要驱动
from selenium import webdriver
from poium import Page, Element, Elements
# page层定义
class BaiduPage(Page):
...
dr = webdriver.Firefox()
LP = BaiduPage(dr) # <--- LP 需要 驱动 `dr`
LP.open("https://www.baidu.com")
from poium.
是的,后来查了一下,加上继承就好了
from poium import Page, Element
from Conf.dataConfig import *
class LoginPage(Page):
def __init__(self, driver):
super().__init__(driver)
self.driver = driver
from poium.
不过其实这里我有个疑问,LoginPage继承的是Page
class LoginPage(Page):
def __init__(self, driver):
super().__init__(driver)
self.driver = driver
Page又是继承的PageBase,Pagebase里面有这一段,为啥LoginPage还要driver?
class PageBase(object):
"""
Page Object pattern.
"""
def __init__(self, driver, url=None, print_log: bool = False):
"""
:param driver: `selenium.webdriver.WebDriver` Selenium webdriver instance
:param url: `str`
:param print_log: `bool` Need to be turned on when used with the seldom framework
Root URI to base any calls to the ``PageObject.get`` method. If not defined
in the constructor it will try and look it from the webdriver object.
"""
self.driver = driver
self.root_uri = url if url else getattr(self.driver, 'url', None)
config.printLog = print_log
是因为conf里面的driver = None吗?
class Browser:
# Default browser driver
driver = None
那我下面这样处理可以吗?
import unittest
from selenium import webdriver
class TestDriverClass(unittest.TestCase):
option = webdriver.ChromeOptions()
# 设置为无头模式运行
option.add_argument("--headless")
# 设置每个用例运行后不关闭浏览器
option.add_experimental_option("detach", True)
option.add_argument(
f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
# 指定driver路径
driver = webdriver.Chrome(options=option, executable_path=r'../driver_tools/chromedriver.exe')
def setUp(self, driver=driver) -> None:
self.driver = driver
windows_size = self.driver.get_window_size('current')
print(windows_size)
# 有头模式下设置窗口大小
# self.driver.maximize_window()
# 无头模式下设置
self.driver.set_window_size(1300, 800)
def tearDown(self, driver=driver) -> None:
self.driver = driver
self.driver.refresh()
from poium.
Related Issues (20)
- 能不能加一个把日志同时输出到文件啊
- execut_script() TypeError:Object of type Element is not json serializable HOT 1
- log 输出乱码[32mINFO ✅ Find element: id=kw [0m 怎么去掉? HOT 2
- poium 能和 behave 一起使用吗
- 【功能】CSSElement 提供获取输入框内容的方法 HOT 1
- 【功能】实现移动端口keyevent 操作 HOT 1
- 【升级】支持selenium 4.0 版本 HOT 1
- Element.get_attribute(name)不可用 HOT 2
- Element.value_of_css_property的返回值应是property_value而非property_name HOT 3
- [提问]如何使用Elements class来获取元素的个数
- 单个元素的定位,返回类型是poium Element,导致调selenium的drag_and_drop 报错move_to requires a WebElement HOT 1
- Elements定位元素时,执行时,没有输出log.info HOT 1
- 用golang重写poium难吗 HOT 1
- 页面跳转后元素定位怎么处理? HOT 4
- 有方法可以判断element不存在吗? Element()初始化会报index out of range HOT 3
- 能否把__get_element()方法public出来,以便扩展和调用。
- 能否与DrissionPage 工具兼容?https://pypi.org/project/DrissionPage/ HOT 4
- Element.select_all 方法缺少grid的判断
- 返回的类型为什么会没统一
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from poium.