本文整理汇总了Python中selenium.webdriver.remote.webdriver.WebDriver方法的典型用法代码示例。如果您正苦于以下问题:Python webdriver.WebDriver方法的具体用法?Python webdriver.WebDriver怎么用?Python webdriver.WebDriver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.remote.webdriver
的用法示例。
在下文中一共展示了webdriver.WebDriver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: auth_driver
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def auth_driver(driver: WebDriver, user: "User") -> WebDriver:
"""
Default AuthDriverFuncType type that sets a session cookie flask-login style
:return: WebDriver
"""
if user:
# Set the cookies in the driver
for cookie in get_auth_cookies(user):
info = dict(name="session", value=cookie)
driver.add_cookie(info)
elif request.cookies:
cookies = request.cookies
for k, v in cookies.items():
cookie = dict(name=k, value=v)
driver.add_cookie(cookie)
return driver
示例2: create
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def create(self) -> WebDriver:
if self._driver_type == "firefox":
driver_class = firefox.webdriver.WebDriver
options = firefox.options.Options()
elif self._driver_type == "chrome":
driver_class = chrome.webdriver.WebDriver
options = chrome.options.Options()
arg: str = f"--window-size={self._window[0]},{self._window[1]}"
options.add_argument(arg)
else:
raise Exception(f"Webdriver name ({self._driver_type}) not supported")
# Prepare args for the webdriver init
options.add_argument("--headless")
kwargs: Dict[Any, Any] = dict(options=options)
kwargs.update(current_app.config["WEBDRIVER_CONFIGURATION"])
logger.info("Init selenium driver")
return driver_class(**kwargs)
示例3: instance
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def instance(self) -> WebDriver:
if self._closed:
raise RuntimeError(
'Webdriver has been closed. '
'You need to call open(url) '
'to open a browser again.'
)
if not self.has_webdriver_started():
raise RuntimeError(
f'No webdriver is bound to current process: '
f'{multiprocessing.current_process().pid}. '
f'You need to call .open(url) first.'
)
return self._stored
示例4: __init__
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def __init__(self,
driver: Optional[WebDriver] = None,
timeout: int = 4,
hook_wait_failure: Optional[Callable[[TimeoutException], Exception]] = None,
base_url: str = '',
set_value_by_js: bool = False,
type_by_js: bool = False,
window_width: Optional[int] = None,
window_height: Optional[int] = None,
):
self._driver = driver
self._timeout = timeout
self._hook_wait_failure = hook_wait_failure
self._base_url = base_url
self._set_value_by_js = set_value_by_js
self._type_by_js = type_by_js
self._window_width = window_width
self._window_height = window_height
示例5: webdriver
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def webdriver():
return mock.Mock(spec=WebDriver)
示例6: test_from_webdriver
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def test_from_webdriver(self):
class TestPage(Page):
pass
webdriver = mock.Mock(spec=WebDriver, url="http://example.com/foo")
page = TestPage(webdriver)
assert page.root_uri == 'http://example.com/foo'
示例7: get_element
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def get_element(self, driver: WebDriver, element: WebElement, save_location: str, to_hide: list = None) -> str:
"""
Usage:
Capture Element screenshot as a image
Args:
driver: Web driver instance
element : The element on web page to be captured
save_location : Path where to save image
Returns:
img_url(str) : The path of image
Raises:
N/A
"""
image = self.full_Screenshot(driver, save_path=save_location, image_name='clipping_shot.png', elements=to_hide)
location = element.location
size = element.size
x = location['x']
y = location['y']
w = size['width']
h = size['height']
width = x + w
height = y + h
image_object = Image.open(image)
image_object = image_object.crop((int(x), int(y), int(width), int(height)))
uid = str(uuid.uuid4())
img_url = os.path.abspath(os.path.join(save_location, f"{uid}.png"))
image_object.save(img_url)
return img_url
示例8: hide_elements
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def hide_elements(driver: WebDriver, elements: list) -> None:
"""
Usage:
Hide elements from web page
Args:
driver : The path of chromedriver
elements : The element on web page to be hide
Returns:
N/A
Raises:
N/A
"""
if elements is not None:
try:
for e in elements:
sp_xpath = e.split('=')
if 'id=' in e.lower():
driver.execute_script(
"document.getElementById('{}').setAttribute('style', 'display:none;');".format(
sp_xpath[1]))
elif 'class=' in e.lower():
driver.execute_script(
"document.getElementsByClassName('{}')[0].setAttribute('style', 'display:none;');".format(
sp_xpath[1]))
else:
print('For Hiding Element works with ID and Class Selector only')
except Exception as Error:
print('Error : ', str(Error))
示例9: before_navigate_to
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def before_navigate_to(self: "TestabilityListener", url: str, driver: WebDriver) -> None:
pass
示例10: after_navigate_to
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def after_navigate_to(self: "TestabilityListener", url: str, driver: WebDriver) -> None:
pass
示例11: before_click
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def before_click(self: "TestabilityListener", element: WebElement, driver: WebDriver) -> None:
pass
示例12: after_click
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def after_click(self: "TestabilityListener", element: WebElement, driver: WebDriver) -> None:
pass
示例13: before_change_value_of
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def before_change_value_of(self: "TestabilityListener", element: WebElement, driver: WebDriver) -> None:
pass
示例14: after_close
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def after_close(self: "TestabilityListener", driver: WebDriver) -> None:
pass
示例15: after_execute_script
# 需要导入模块: from selenium.webdriver.remote import webdriver [as 别名]
# 或者: from selenium.webdriver.remote.webdriver import WebDriver [as 别名]
def after_execute_script(self: "TestabilityListener", script: str, driver: WebDriver) -> None:
pass