本文整理匯總了Python中selenium.webdriver.support.expected_conditions.text_to_be_present_in_element方法的典型用法代碼示例。如果您正苦於以下問題:Python expected_conditions.text_to_be_present_in_element方法的具體用法?Python expected_conditions.text_to_be_present_in_element怎麽用?Python expected_conditions.text_to_be_present_in_element使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類selenium.webdriver.support.expected_conditions
的用法示例。
在下文中一共展示了expected_conditions.text_to_be_present_in_element方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: index_page
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def index_page(page):
try:
print('正在爬取第: %s 頁' % page)
wait.until(
EC.presence_of_element_located((By.ID, "dt_1")))
# 判斷是否是第1頁,如果大於1就輸入跳轉,否則等待加載完成。
if page > 1:
# 確定頁數輸入框
input = wait.until(EC.presence_of_element_located(
(By.XPATH, '//*[@id="PageContgopage"]')))
input.click()
input.clear()
input.send_keys(page)
submit = wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, '#PageCont > a.btn_link')))
submit.click()
time.sleep(2)
# 確認成功跳轉到輸入框中的指定頁
wait.until(EC.text_to_be_present_in_element(
(By.CSS_SELECTOR, '#PageCont > span.at'), str(page)))
except Exception:
return None
示例2: wait_for_text
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def wait_for_text(driver, el_id, value, removed=False, timeout=10):
el = wait_for_element(driver, el_id, timeout)
if value in el.text and not removed:
return el
if removed and value not in el.text:
return el
wait = WebDriverWait(driver, timeout)
condition = EC.text_to_be_present_in_element((By.ID, el_id), value)
if removed:
wait.until_not(condition)
if value not in el.text:
return el
else:
wait.until(condition)
if value in el.text:
return el
raise AttributeError
示例3: wait_for_text
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def wait_for_text(self, selector='', text='', **kwargs):
'''
Wait for an element to contain a specific string.
Parameters
----------
selector: str
A CSS selector to search for. This can be any valid CSS selector.
text: str
The string to look for. This must be precise.
(Case, punctuation, UTF characters... etc.)
kwargs:
Passed on to _wait_for
'''
if selector.startswith('/'):
by = By.XPATH
else:
by = By.CSS_SELECTOR
self._wait_for(EC.text_to_be_present_in_element((by, selector),
text), **kwargs)
示例4: create_attribute
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def create_attribute(self, attribute_key, attribute_value):
# Click in the new attribute dialog
self.selenium.find_element_by_class_name('js-attribute-create').click()
WebDriverWait(self.selenium, 10).until(
EC.text_to_be_present_in_element((By.CLASS_NAME, 'modal-title'),
'Create attribute')
)
# Fill out the form
element = self.selenium.find_element_by_id('id_key')
element.clear()
element.send_keys(attribute_key)
element = self.selenium.find_element_by_id('id_attr_value')
element.clear()
element.send_keys(attribute_value)
# Click in the create attribute button
self.selenium.find_element_by_xpath(
'//div[@class="modal-footer"]/button[normalize-space()="Create '
'attribute"]'
).click()
# Wait for modal to close and for table to refresh
self.wait_close_modal_refresh_table('attribute-table_previous')
示例5: delete_filter
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def delete_filter(self):
# First make sure we are in the filter tab
self.select_filter_tab()
# Click in the delete Icon
self.selenium.find_element_by_class_name('js-filter-delete').click()
# Wait for the confirmation screen
WebDriverWait(self.selenium, 10).until(
EC.text_to_be_present_in_element(
(By.XPATH, '//div[@id="modal-item"]/div/div/form/div/h4'),
'Confirm filter deletion')
)
# Click in the 'delete filter'
self.selenium.find_element_by_xpath(
'//div[@id="modal-item"]//button[normalize-space()="Delete filter"]'
).click()
WebDriverWait(self.selenium, 10).until_not(
EC.visibility_of_element_located((By.ID, 'div-spinner'))
)
self.wait_for_page(element_id='edit-personalized-text-tab-content')
示例6: enter_concert
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def enter_concert(self):
self.login()
try:
if self.type == 1: # detail.damai.cn
locator = (By.XPATH, "/html/body/div[1]/div/div[3]/div[1]/a[2]/div")
elif self.type == 2: # piao.damai.cn
locator = (By.XPATH, "/html/body/div[1]/div/ul/li[2]/div/label/a[2]")
WebDriverWait(self.driver, self.total_wait_time, self.refresh_wait_time).until(
EC.text_to_be_present_in_element(locator, self.nick_name))
self.status = 1
print("###登錄成功###")
except Exception as e:
print(e)
self.status = 0
self.driver.quit()
raise Exception("***錯誤:登錄失敗,請檢查配置文件昵稱或刪除cookie.pkl後重試***")
示例7: wait_for_text
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def wait_for_text(self, css_selector, text, timeout=10):
"""
Helper function that blocks until the text is found in the CSS selector.
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
self.wait_until(
ec.text_to_be_present_in_element(
(By.CSS_SELECTOR, css_selector), text),
timeout
)
示例8: wait_for_text
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def wait_for_text(self, css_selector, text, timeout=10):
"""
Block until the text is found in the CSS selector.
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
self.wait_until(
ec.text_to_be_present_in_element(
(By.CSS_SELECTOR, css_selector), text),
timeout
)
示例9: next_page
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def next_page(self):
next_btn = self.driver.find_element_by_css_selector('button.next')
next_btn.click()
self.wait(EC.text_to_be_present_in_element(
(By.CSS_SELECTOR, '.results-paginator li.page-list li.active'), str(self.page_num + 1)
))
self.page_num += 1
示例10: configure_connection_type
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def configure_connection_type(self):
dropdown_btn = self.wait_for_el(
'.search-s-facet--facetNetwork form button')
if not self.first_only:
return
new_url = re.sub(r'&facetNetwork=(.*?)&',
r'&facetNetwork=%5B"F"%5D&', self.driver.current_url)
self.driver.get(new_url)
self.wait(EC.text_to_be_present_in_element(
(By.CSS_SELECTOR, '.search-s-facet--facetNetwork'), '1st'
))
示例11: element_has_text
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def element_has_text(self, id_, text, timeout=DEFAULT_TIMEOUT):
return WebDriverWait(self.driver, timeout).until(
ec.text_to_be_present_in_element((By.ID, id_), text)
)
示例12: element_with_tag_name_has_text
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def element_with_tag_name_has_text(self, tag_name, text, timeout=DEFAULT_TIMEOUT):
return WebDriverWait(self.driver, timeout).until(
ec.text_to_be_present_in_element((By.TAG_NAME, tag_name), text)
)
示例13: next_page
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def next_page(page_num):
try:
print('獲取下一頁數據')
next_btn = WAIT.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#server-search-app > div.contain > div.body-contain > div > div.page-wrap > div > ul > li.page-item.next > button')))
next_btn.click()
WAIT.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#server-search-app > div.contain > div.body-contain > div > div.page-wrap > div > ul > li.page-item.active > button'),str(page_num)))
get_source()
except TimeoutException:
browser.refresh()
return next_page(page_num)
示例14: next_page
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def next_page(page_num):
try:
print('獲取下一頁數據')
next_btn = WAIT.until(EC.element_to_be_clickable((By.CSS_SELECTOR,
'#all-list > div.flow-loader > div.page-wrap > div > ul > li.page-item.next > button')))
next_btn.click()
WAIT.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR,
'#all-list > div.flow-loader > div.page-wrap > div > ul > li.page-item.active > button'),
str(page_num)))
get_source()
except TimeoutException:
browser.refresh()
return next_page(page_num)
示例15: delete_condition
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import text_to_be_present_in_element [as 別名]
def delete_condition(self, cname):
"""
Given a condition name, search for it in the right DIV and click the
buttons to remove it.
:param cname: Condition name
:return:
"""
self.select_condition_tab()
# Get the button for the condition
self.selenium.find_element_by_xpath(
'//*[contains(@class, "card-header") and text() = "{0}"]/'
'../div[@class = "cond-buttons"]/'
'button[contains(@class, "js-condition-delete")]'.format(cname),
).click()
# Wait for the screen to delete the condition
WebDriverWait(self.selenium, 10).until(
EC.text_to_be_present_in_element(
(By.XPATH, '//div[@id="modal-item"]/div/div/form/div/h4'),
'Confirm condition deletion')
)
# Click in the confirm button
self.selenium.find_element_by_xpath(
'//div[@id="modal-item"]//button[normalize-space()="Delete '
'condition"]'
).click()
self.wait_for_page(element_id='edit-personalized-text-tab-content')