本文整理汇总了Python中selenium.webdriver.support.wait.WebDriverWait类的典型用法代码示例。如果您正苦于以下问题:Python WebDriverWait类的具体用法?Python WebDriverWait怎么用?Python WebDriverWait使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebDriverWait类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_all_admin_pages
def test_check_all_admin_pages(self):
wait = WebDriverWait(self.driver, 5)
self.driver.get(SIGN_IN_PAGE)
self.driver.find_element_by_name("username").send_keys(LOGIN)
self.driver.find_element_by_name("password").send_keys(PASSWORD)
self.driver.find_element_by_name("login").click()
first_menu_elements = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "#app->a")))
first_menu_links = [x.get_attribute("href") for x in first_menu_elements]
for link in first_menu_links:
self.driver.get(link)
first_menu_item_header = self.driver.find_elements_by_css_selector("#content>h1")
self.assertTrue(first_menu_item_header)
second_menu_elements = self.driver.find_elements_by_css_selector(".docs a")
second_menu_links = [x.get_attribute("href") for x in second_menu_elements]
if second_menu_elements:
for link in second_menu_links:
self.driver.get(link)
second_menu_item_header = self.driver.find_elements_by_css_selector("#content>h1")
self.assertTrue(second_menu_item_header)
示例2: __init__
def __init__(self):
name = ""
pw = ""
while((name == "") | (pw == "")):
name = input("Loginname: ")
print("Login :", name)
pw = input("Password: ")#TODO: nicer password taking
print("PW :", pw)
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 (KHTML, like Gecko) Chrome/15.0.87")
self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true'])
#goto isis page because direct access is not permitted
self.driver.get("https://isis.tu-berlin.de/")
#wait until page is up
wait = WebDriverWait(self.driver, 10)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.content")))
#click shibbolethbutton to go to login page
self.driver.find_element_by_id('shibbolethbutton').click()
# Fill the login form and submit it
self.driver.find_element_by_name('j_username').send_keys(name)
self.driver.find_element_by_id('password').send_keys(pw)
self.driver.find_element_by_name('Submit').submit()
示例3: get_max_page_num
def get_max_page_num(self):
max_num = WebDriverWait(self.driver, 20, 0.1).until(
lambda d: d.find_element_by_class_name(self.TOTAL_NUM))
size = max_num.get_attribute("innerText")
if not size:
size = max_num.text
return int(size)
示例4: test_onclick_popup_modal_and_presents_articles_titles
def test_onclick_popup_modal_and_presents_articles_titles(self):
# self.create_database_record()
# Visitor goes to home page and clicks on airplane word.
self.browser.get(self.live_server_url)
self.get_word('airplane').click()
# Visitor waits until modal windows pop up.
block = WebDriverWait(self.browser, 10)
modal = block.until(expected_conditions.visibility_of_element_located((By.ID, 'word-details-modal')))
# Visitor gets articles titles.
self.check_for_title_in_article_table('airplane is faster than ship.')
self.check_for_title_in_article_table('airplane crashed yesterday.')
self.check_title_does_not_exist_in_article_table('rocket took off today morning.')
# Visitor closes modal window, refreshes browser and clicks on rocket word.
self.browser.find_element(By.XPATH, '//button[@class="btn btn-default"]').click()
self.browser.refresh()
self.browser.find_element_by_link_text('rocket').click()
# Visitor waits until modal windows pop up.
block = WebDriverWait(self.browser, 10)
modal = block.until(expected_conditions.visibility_of_element_located((By.ID, 'word-details-modal')))
# Visitor gets articles titles.
self.check_title_does_not_exist_in_article_table('airplane is faster than ship.')
self.check_title_does_not_exist_in_article_table('airplane crashed yesterday.')
self.check_for_title_in_article_table('rocket took off today morning.')
示例5: wait_until_element_not_visible
def wait_until_element_not_visible(webdriver, locator_lambda_expression,
timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5):
"""
Wait for a WebElement to disappear.
Args:
webdriver (Webdriver) - Selenium Webdriver
locator (lambda) - Locator lambda expression.
Kwargs:
timeout (number) - timeout period
sleep (number) - sleep period between intervals.
"""
# Wait for loading progress indicator to go away.
try:
stoptime = datetime.now() + timedelta(seconds=timeout)
while datetime.now() < stoptime:
element = WebDriverWait(webdriver, WTF_TIMEOUT_MANAGER.BRIEF).until(
locator_lambda_expression)
if element.is_displayed():
time.sleep(sleep)
else:
break
except TimeoutException:
pass
示例6: _attempt_download
def _attempt_download(self, query, offset):
real_offset = self._calculate_real_offset(offset)
real_offset = int(real_offset)
dictionary = {AbsWebsiteCommonApi._QUERY_MASK: query, AbsWebsiteCommonApi._OFFSET_MASK: str(real_offset)}
url = self._multiple_replace(dictionary, self.base_url)
page_source = None
for i in range(0, AbsWebsiteCommonApi._DOWNLOAD_TRY_NUMBER):
time.sleep(AbsWebsiteCommonApi._CRAWL_DELAY)
web_page = None
try:
web_page = webdriver.PhantomJS()
web_page.get(url)
wait = WebDriverWait(web_page, AbsWebsiteCommonApi._PAGE_LOAD_TIMEOUT)
wait.until(self.test_page_loaded)
except Exception as exception:
print(str(exception))
if web_page is not None:
web_page.close()
page_source = None
continue
page_source = web_page.execute_script(AbsWebsiteCommonApi._JAVASCRIPT_GET_PAGE_SOURCE_CODE)
web_page.close()
self.inc_download()
break
if page_source is None:
print("ERROR - Internet connection failure")
os.kill(os.getpid(), signal.SIGUSR1)
return page_source
示例7: add_service
def add_service(self):
count = self.items_in_cart()
Find(by=By.CSS_SELECTOR, value='.add-to-cart', context=self).click()
if not self.item_is_sold_out():
wait = WebDriverWait(self._driver, 10)
wait.until(lambda x: count < self.items_in_cart())
示例8: test_sort_routes
def test_sort_routes(self):
wait = WebDriverWait(self.driver, 15)
self.click_first_nearby_stop('Taipei Station')
wait.until(
lambda driver: self.driver.find_element_by_id('nexti.android.bustaipei:id/menu_passby_sort')
).click()
sleep(0.5)
estimates = self.driver.find_elements_by_id('nexti.android.bustaipei:id/text_estimate')
current_estimate = 0
is_depart = False
serv_over = False
for estimate in estimates:
if is_depart:
self.assertEqual(estimate.text, 'Depart')
elif serv_over:
self.assertEqual(estimate.text, 'Serv Over')
if estimate.text == 'Depart':
is_depart = True
continue
elif estimate.text == 'Serv Over':
serv_over = True
continue
elif estimate.text == 'Approach':
continue
match = re.search('(\d{0,2}) min', estimate.text)
next_estimate = int(match.group(1))
self.assertLessEqual(current_estimate, next_estimate)
current_estimate = next_estimate
示例9: setUp
def setUp(self):
super().setUp()
wait = WebDriverWait(self.driver, 15)
button = wait.until(
lambda driver: self.driver.find_element_by_android_uiautomator('new UiSelector().text("Nearby")')
)
button.click()
示例10: is_checked
def is_checked(self, compared_to_average):
checkbox = WebDriverWait(self.driver, 30, 0.5).until(
lambda d: d.find_elements_by_css_selector(self.COMPARED_TO_AVERAGE)[compared_to_average]
)
if checkbox.is_selected():
return True
return False
示例11: is_business_node_checked
def is_business_node_checked(self, business_node_number):
checkbox = WebDriverWait(self.driver, 30, 0.5).until(
lambda d: d.find_elements_by_css_selector(self.BUSINESS_NODES_CHECKBOXES)[business_node_number + 1]
)
if checkbox.is_selected():
return True
return False
示例12: test_compare_products_removal_alert
def test_compare_products_removal_alert(self):
# get the search textbox
search_field = self.driver.find_element_by_name("q")
search_field.clear()
# enter search keyword and submit
search_field.send_keys("phones")
search_field.submit()
# click the Add to compare link
self.driver.\
find_element_by_link_text("Add to Compare").click()
# click on Remove this item link, this will display # an alert to the user
self.driver.find_element_by_link_text("Clear All").click()
# switch to the alert
#alert = self.driver.switch_to_alert()
alert = WebDriverWait(self.driver,10).until(expected_conditions.alert_is_present())
# get the text from alert
alert_text = alert.text
# check alert text
self.assertEqual("Are you sure you would like to remove all products from your comparison?", alert_text)
# click on Ok button
alert.accept()
示例13: publish
def publish(link):
driver.get(link)
find_click(".org-module-link[href*=members]")
type(".auto-search-input", username)
l = lambda _driver: _driver.find_element_by_css_selector("a[href*=publicize]")
elm = WebDriverWait(driver, 25).until(l)
elm.click()
示例14: get
def get(self, url):
super(WebDriverMixin, self).get('about:blank')
full_url = urljoin(self._base_url, url)
self.execute_script(
"""
window.name = "{}" + window.name;
window.location.replace("{}");
""".format(DEFER_LABEL, full_url)
)
wait = WebDriverWait(self, 10)
wait.until_not(self._location_equals, 'about:blank')
if not self.ignore_synchronization:
test_result = self._test_for_angular()
angular_on_page = test_result[0]
if not angular_on_page:
message = test_result[1]
raise AngularNotFoundException(
'Angular could not be found on page: {}:'
' {}'.format(full_url, message)
)
# TODO: inject scripts here
# return self.execute_script(
# 'angular.resumeBootstrap(arguments[0]);'
# )
self.execute_script('angular.resumeBootstrap();')
示例15: finds
def finds( identifier, context=None, timeout=-1, condition=None):
"""
@return: Returns the web element found by identifier
@rtype: selenium.webdriver.remote.webelement.WebElement
"""
if timeout == -1:
timeout = default_timeout
if isinstance(identifier, WebElement):
return identifier
if context is None:
context = driver
locator = get_identifier(identifier)
if condition is None:
condition = count_non_zero_and_visible(locator)
else:
condition = condition(locator)
wdw = WebDriverWait(driver, timeout)
try:
elems = wdw.until(condition)
return elems if isinstance(elems, list) else []
except TimeoutException:
return []