本文整理汇总了Python中selenium.webdriver方法的典型用法代码示例。如果您正苦于以下问题:Python selenium.webdriver方法的具体用法?Python selenium.webdriver怎么用?Python selenium.webdriver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium
的用法示例。
在下文中一共展示了selenium.webdriver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def __init__(self, configuration):
self.timeout = 10
'''
# NOTE : selenium.webdriver methods/properties
add_cookie, application_cache, back, binary, capabilities, close,
command_executor, create_web_element, current_url, current_window_handle, delete_all_cookies,
delete_cookie, desired_capabilities, error_handler, execute, execute_async_script, execute_script,
file_detector, file_detector_context, find_element, find_element_by_class_name, find_element_by_css_selector,
find_element_by_id, find_element_by_link_text, find_element_by_name, find_element_by_partial_link_text,
find_element_by_tag_name, find_element_by_xpath, find_elements, find_elements_by_class_name,
find_elements_by_css_selector, find_elements_by_id, find_elements_by_link_text, find_elements_by_name,
find_elements_by_partial_link_text, find_elements_by_tag_name, find_elements_by_xpath, firefox_profile,
forward, get, get_cookie, get_cookies, get_log, get_screenshot_as_base64, get_screenshot_as_file,
get_screenshot_as_png, get_window_position, get_window_size, implicitly_wait, log_types, maximize_window,
mobile, name, options, orientation, page_source, profile, quit, refresh, save_screenshot, session_id,
set_context, set_page_load_timeout, set_script_timeout, set_window_position, set_window_size, start_client,
start_session, stop_client, switch_to, switch_to_active_element, switch_to_alert, switch_to_default_content,
switch_to_frame, switch_to_window, title, w3c, window_handles
'''
示例2: go_to_specific_results_page
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def go_to_specific_results_page(driver, delay, results_page):
"""
go to a specific results page in case of an error, can restart
the webdriver where the error occurred.
"""
if results_page < 2:
return
current_page = 1
for i in range(results_page):
current_page += 1
time.sleep(5)
try:
next_results_page(driver, delay)
print("\n**************************************************")
print("\n\n\nNavigating to results page {}" \
"\n\n\n".format(current_page))
except ValueError:
print("**************************************************")
print("\n\n\n\n\nSearch results exhausted\n\n\n\n\n")
示例3: test_dataset_file_browser
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def test_dataset_file_browser(driver: selenium.webdriver, *args, **kwargs):
"""
Test that a file can be dragged and dropped into data in a dataset.
Args:
driver
"""
username = testutils.log_in(driver)
testutils.GuideElements(driver).remove_guide()
dataset_elts = testutils.DatasetElements(driver)
dataset_title = dataset_elts.create_dataset()
logging.info(f"Navigating to data for dataset {dataset_title}")
driver.get(f"{os.environ['GIGANTUM_HOST']}/datasets/{username}/{dataset_title}/data")
file_browser_elts = testutils.FileBrowserElements(driver)
file_browser_elts.file_browser_area.wait_to_appear()
logging.info(f"Dragging and dropping file into data for dataset {dataset_title}")
file_browser_elts.drag_drop_file_in_drop_zone()
assert file_browser_elts.file_information.find().text == 'sample-upload.txt', \
"Expected sample-upload.txt to be the first file in Data"
示例4: test_create_local_branch
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def test_create_local_branch(driver: selenium.webdriver, *args, **kwargs):
"""
Test the creation of a local branch.
Args:
driver
"""
r = testutils.prep_py3_minimal_base(driver)
username, project_name = r.username, r.project_name
branch_elts = testutils.BranchElements(driver)
branch_elts.create_local_branch("test-branch")
logging.info("Checking that you are on the new branch and that the new branch is local only")
assert branch_elts.upper_left_branch_name.find().text == "test-branch", \
"Expected to be on test-branch, upper left"
assert branch_elts.upper_left_branch_local_only.find(), "Expected test-branch to be local only, upper left"
branch_elts.manage_branches_button.wait_to_appear().click()
branch_elts.manage_branches_modal.wait_to_appear()
assert branch_elts.manage_branches_branch_name.find().text == "test-branch", \
"Expected to be on test-branch, manage branches"
assert branch_elts.manage_branches_local_only.find(), "Expected test-branch to be local only, manage branches"
示例5: test_edge_build_versions
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def test_edge_build_versions(driver: selenium.webdriver, *args, **kwargs):
"""
Test that the requests edge build version matches the selenium edge build version.
Args:
driver
"""
host = f"{os.environ['GIGANTUM_HOST']}/api/ping"
logging.info("Getting requests edge build version")
r = requests.get(host)
if r.status_code != 200:
logging.error(f"Gigantum is not found at {host}")
sys.exit(1)
requests_edge_build_version = json.loads(r.text)
logging.info("Getting selenium edge build version")
driver.get(host)
time.sleep(2)
if driver.name == "firefox":
driver.find_element_by_css_selector("#rawdata-tab").click()
selenium_edge_build_version = json.loads(driver.find_element_by_css_selector("pre").text)
assert requests_edge_build_version == selenium_edge_build_version, \
"requests edge build version does not match selenium edge build version"
示例6: test_import_projects_via_zip_file
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def test_import_projects_via_zip_file(driver: selenium.webdriver, *args, **kwargs):
"""
Test that projects can be imported via zip file and that they build successfully.
Args:
driver
"""
project_zip_file = "sample-prj-93f4b4.zip"
file_path = os.path.abspath(os.path.join(__file__, f"../../../resources/{project_zip_file}"))
username = testutils.log_in(driver)
testutils.GuideElements(driver).remove_guide()
try:
import_project_elts = testutils.ImportProjectElements(driver)
import_project_elts.import_project_via_zip_file_drag_and_drop(file_path)
project_control = testutils.ProjectControlElements(driver)
assert project_control.container_status_stopped.find().is_displayed(), \
f"Project {project_zip_file} was not imported successfully via zip file"
finally:
try:
delete_local_project(username, "sample-prj")
except Exception as e:
logging.error(f"Failed to delete project {username}/'sample-prj': {e}")
示例7: test_valid_custom_docker
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def test_valid_custom_docker(driver: selenium.webdriver, *args, **kwargs):
"""
Test valid custom Docker instructions.
Args:
driver
"""
r = testutils.prep_py3_minimal_base(driver)
username, project_title = r.username, r.project_name
env_elts = testutils.EnvironmentElements(driver)
env_elts.add_custom_docker_instructions(username, project_title,
"RUN cd /tmp && "
"git clone https://github.com/gigantum/confhttpproxy && "
"cd /tmp/confhttpproxy && pip install -e.")
project_control_elts = testutils.ProjectControlElements(driver)
project_control_elts.container_status_stopped.wait_to_appear(60)
container_status = project_control_elts.container_status_stopped.find().is_displayed()
assert container_status, "Expected stopped container status"
示例8: prep_base
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def prep_base(driver, base_button_check, skip_login=False):
"""Create a new project from the UI and wait until it builds successfully
Args:
driver: Selenium webdriver
base_button_check: Lambda which gives identifier to element in selection menu.
skip_login: If true, assume you are already logged in
"""
username = None
if skip_login is False:
username = log_in(driver)
elements.GuideElements(driver).remove_guide()
else:
time.sleep(3)
proj_name = create_project_without_base(driver)
time.sleep(7)
select_project_base(driver, base_button_check())
# assert container status is stopped
project_elts = elements.ProjectControlElements(driver)
# This will throw an exception on time-out
project_elts.container_status_stopped.wait_to_appear(300)
return ProjectPrepResponse(username=username, project_name=proj_name)
示例9: create_project_without_base
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def create_project_without_base(driver: selenium.webdriver) -> str:
"""
Create a project without a base.
Args:
driver
Returns:
Name of project just created
"""
unique_project_name = testutils.unique_project_name()
logging.info(f"Creating a new project: {unique_project_name}")
project_elts = elements.AddProjectElements(driver)
project_elts.create_new_button.click()
project_elts.project_title_input.click()
project_elts.project_title_input.find().send_keys(unique_project_name)
project_elts.project_description_input.click()
project_elts.project_description_input.find().send_keys(testutils.unique_project_description())
project_elts.project_continue_button.click()
return unique_project_name
示例10: delete_dataset_cloud
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def delete_dataset_cloud(driver: selenium.webdriver, dataset_title):
"""
Delete a dataset from cloud.
Args:
driver
dataset
"""
logging.info(f"Removing dataset {dataset_title} from cloud")
driver.find_element_by_xpath("//a[contains(text(), 'Datasets')]").click()
driver.find_element_by_css_selector(".Datasets__nav-item--cloud").click()
time.sleep(2)
driver.find_element_by_css_selector(".RemoteDatasets__icon--delete").click()
driver.find_element_by_css_selector("#deleteInput").send_keys(dataset_title)
time.sleep(2)
driver.find_element_by_css_selector(".ButtonLoader").click()
time.sleep(5)
wait = WebDriverWait(driver, 200)
wait.until(EC.invisibility_of_element_located((By.CSS_SELECTOR, ".DeleteDataset")))
示例11: __init__
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def __init__(self,domain_name,page_results,exts,download_dir,webdriver):
"""Everything that should be initiated with a new object goes here.
Parameters:
domain_name The domain name to search under for files
page_results A limit on the number of search page results to request and parse
exts A list of file type extensions for the searches
download_dir The directory to use for the downloaded files
webdriver A Selenium webdriver object to use for the web browsing
"""
self.exts = exts
self.container = list()
self.browser = webdriver
self.domain_name = domain_name
self.page_results = page_results
self.download_dir = download_dir + "file_downloads/"
示例12: testGETXSSDriver
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def testGETXSSDriver(url: str, cookies: Mapping[str, str], driver: webdriver) -> Optional[str]:
""" If the given URL pops an alert box when accessed with the given cookies, return the contents of the alert box,
otherwise return None """
driver.setCookies(url, cookies)
try:
driver.get(url)
WebDriverWait(driver, config.timeout).until(expected_conditions.alert_is_present())
# Note that despite the name switch_to_alert also handles prompt:
# - http://selenium-python.readthedocs.io/navigating.html#popup-dialogs
alert = driver.switch_to_alert()
text = alert.text
driver.reset()
return text
except (TimeoutException, URLError):
driver.reset()
return None
示例13: testPOSTXSSDriver
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def testPOSTXSSDriver(url: str, cookies: Mapping[str, str], data: Mapping[str, str], driver: webdriver) -> \
Optional[str]:
""" If the given URL pops an alert box when accessed with the given cookies, return the contents of the alert box,
otherwise return None """
driver.setCookies(url, cookies)
try:
driver.post(url, data)
WebDriverWait(driver, config.timeout).until(expected_conditions.alert_is_present())
# Note that despite the name switch_to_alert also handles prompt:
# - http://selenium-python.readthedocs.io/navigating.html#popup-dialogs
alert = driver.switch_to_alert()
text = alert.text
driver.reset()
return text
except (TimeoutException, URLError):
driver.reset()
return None
示例14: install
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def install(self, patch_selenium=True):
"""
Initialize the patch
This will:
download chromedriver if not present
patch the downloaded chromedriver
patch selenium package if <patch_selenium> is True (default)
:param patch_selenium: patch selenium webdriver classes for Chrome and ChromeDriver (for current python session)
:return:
"""
if not os.path.exists(self.executable_path):
self.fetch_chromedriver()
self.patch_binary()
self.__class__.installed = True
if patch_selenium:
self.patch_selenium_webdriver()
示例15: get_html
# 需要导入模块: import selenium [as 别名]
# 或者: from selenium import webdriver [as 别名]
def get_html(self):
""" Downloads HTML content of page given the page_url"""
if self.use_ghost:
self.url = urljoin("http://", self.url)
import selenium
import selenium.webdriver
driver = selenium.webdriver.PhantomJS(
service_log_path=os.path.devnull)
driver.get(self.url)
page_html = driver.page_source
page_url = driver.current_url
driver.quit()
else:
if self.proxy_url:
print("Using proxy: " + self.proxy_url + "\n")
try:
page = requests.get(self.url, proxies=self.proxies)
if page.status_code != 200:
raise PageLoadError(page.status_code)
except requests.exceptions.MissingSchema:
self.url = "http://" + self.url
page = requests.get(self.url, proxies=self.proxies)
if page.status_code != 200:
raise PageLoadError(page.status_code)
except requests.exceptions.ConnectionError:
raise PageLoadError(None)
try:
page_html = page.text
page_url = page.url
except UnboundLocalError:
raise PageLoadError(None)
self.page_html = page_html
self.page_url = page_url
return (self.page_html, self.page_url)