Python selenium.webdriver.support.expected_conditions.text_to_be_present_in_element() Examples
The following are 28
code examples of selenium.webdriver.support.expected_conditions.text_to_be_present_in_element().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
selenium.webdriver.support.expected_conditions
, or try the search function
.
Example #1
Source File: eastmoney_crawler.py From eastmoney_spider with MIT License | 8 votes |
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
Example #2
Source File: Autoticket.py From Autoticket with MIT License | 7 votes |
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后重试***")
Example #3
Source File: __init__.py From ontask_b with MIT License | 7 votes |
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')
Example #4
Source File: __init__.py From ontask_b with MIT License | 6 votes |
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')
Example #5
Source File: WebRunner.py From PyWebRunner with MIT License | 6 votes |
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)
Example #6
Source File: pytest_dallinger.py From Dallinger with MIT License | 6 votes |
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
Example #7
Source File: basewebobject.py From avos with Apache License 2.0 | 5 votes |
def _wait_till_text_present_in_element(self, locator, text): condition = expected_conditions.text_to_be_present_in_element(locator, text) try: wait.WebDriverWait(self.driver, self.explicit_wait).\ until(condition) except Exceptions.TimeoutException: return False return True
Example #8
Source File: ConnectionScraper.py From scrape-linkedin-selenium with MIT License | 5 votes |
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' ))
Example #9
Source File: conditions.py From behave-webdriver with MIT License | 5 votes |
def __call__(self, driver): """ Same logic as in EC.text_to_be_present_in_element except StaleElementReferenceException is not caught this, for now, is needed to distinguish if a False return value is the result of this exception. """ try: element = driver.find_element(*self.locator) result = bool(element.text) except StaleElementReferenceException: return False if self.negative: return not result return result
Example #10
Source File: __init__.py From product-database with MIT License | 5 votes |
def wait_for_text_to_be_displayed_in_body_tag(browser, text): try: WebDriverWait(browser, 30).until( EC.text_to_be_present_in_element((By.TAG_NAME, "body"), text) ) except TimeoutException: print(browser.find_element_by_tag_name("body").text) pytest.fail("expected text '%s' was not visible within 10 seconds")
Example #11
Source File: __init__.py From product-database with MIT License | 5 votes |
def wait_for_text_to_be_displayed_in_id_tag(browser, component_id, text): try: WebDriverWait(browser, 30).until( EC.text_to_be_present_in_element((By.ID, component_id), text) ) except TimeoutException: print(browser.find_element_by_tag_name("body").text) pytest.fail("expected text '%s' was not visible within 10 seconds")
Example #12
Source File: core_test.py From tensorboard with Apache License 2.0 | 5 votes |
def testLogdirDisplays(self): self.wait.until( expected_conditions.text_to_be_present_in_element( (by.By.ID, "data_location"), self.logdir ) )
Example #13
Source File: core_test.py From tensorboard with Apache License 2.0 | 5 votes |
def testToolbarTitleDisplays(self): self.wait.until( expected_conditions.text_to_be_present_in_element( (by.By.CLASS_NAME, "toolbar-title"), "TensorBoard" ) )
Example #14
Source File: tests.py From python2017 with MIT License | 5 votes |
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 )
Example #15
Source File: tests.py From openhgsenti with Apache License 2.0 | 5 votes |
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 )
Example #16
Source File: create_screen_captures.py From ontask_b with MIT License | 5 votes |
def test_ss_01(self): """ Create a workflow, upload data and merge :return: """ # Login self.login('instructor01@bogus.com') # Open Import page self.selenium.find_element_by_link_text('Import workflow').click() WebDriverWait(self.selenium, 10).until( EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"), 'Import workflow') ) # # Import workflow # self.selenium.find_element_by_id('id_name').send_keys( self.workflow_name ) self.selenium.find_element_by_id('id_wf_file').send_keys( os.path.join(settings.BASE_DIR(), 'initial_workflow.gz') ) # Picture of the body self.body_ss('workflow_import.png') # Click the import button self.selenium.find_element_by_xpath( "//form/div/button[@type='Submit']" ).click() self.wait_for_page(title='OnTask :: Workflows') # End of session self.logout()
Example #17
Source File: __init__.py From ontask_b with MIT License | 5 votes |
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')
Example #18
Source File: tests.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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 )
Example #19
Source File: tests.py From python with Apache License 2.0 | 5 votes |
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 )
Example #20
Source File: ConnectionScraper.py From scrape-linkedin-selenium with MIT License | 5 votes |
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
Example #21
Source File: tests.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
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 )
Example #22
Source File: ikun_basketball.py From learn_python3_spider with MIT License | 5 votes |
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)
Example #23
Source File: caixukun.py From Python-Code with MIT License | 5 votes |
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)
Example #24
Source File: conftest.py From vue.py with MIT License | 5 votes |
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) )
Example #25
Source File: conftest.py From vue.py with MIT License | 5 votes |
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) )
Example #26
Source File: test_live.py From ontask_b with MIT License | 4 votes |
def test_send_email(self): # Login self.login('instructor01@bogus.com') # GO TO THE WORKFLOW PAGE self.access_workflow_from_home_page(self.wflow_name) # Goto the action page self.go_to_actions() # Click in the page to send email self.open_action_run(self.action_name) self.wait_for_datatable('email-action-request-data') # Set the subject of the email self.selenium.find_element_by_id('id_subject').send_keys('Subject TXT') # Set the email column select = Select(self.selenium.find_element_by_id( 'id_item_column')) select.select_by_visible_text('email') # Tick the track email self.selenium.find_element_by_id('id_track_read').click() # Click the send button self.selenium.find_element_by_xpath( "//button[normalize-space()='Send']").click() WebDriverWait(self.selenium, 10).until( EC.text_to_be_present_in_element( (By.XPATH, "//body/div/h1"), 'Action scheduled for execution') ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) # There should be a message on that page self.assertTrue( self.selenium.find_element_by_xpath( "//div[@id='action-run-done']/div/a" ).text.startswith( 'You may check the status in log number' ) ) # Check that the email has been properly stored assert len(mail.outbox) == 3 # Go to the table page self.go_to_table() # There should be a column for the email tracking # This column is now added by Celery which needs to be running # with the same DB configuration (which is not). # self.assertIn('EmailRead_1', self.selenium.page_source) # End of session self.logout()
Example #27
Source File: utils.py From anvio with GNU General Public License v3.0 | 4 votes |
def run_selenium_and_export_svg(url, output_file_path, browser_path=None, run=run): if filesnpaths.is_file_exists(output_file_path, dont_raise=True): raise FilesNPathsError("The output file already exists. Anvi'o does not like overwriting stuff.") filesnpaths.is_output_file_writable(output_file_path) try: from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException except: raise ConfigError("You want to export SVGs? Well, you need the Python library 'selenium' to be able to " "do that but you don't have it. If you are lucky, you probably can install it by " "typing 'pip install selenium' or something :/") if browser_path: filesnpaths.is_file_exists(browser_path) run.info_single('You are launching an alternative browser. Keep an eye on things!', mc='red', nl_before=1) driver = webdriver.Chrome(executable_path=browser_path) else: driver = webdriver.Chrome() driver.wait = WebDriverWait(driver, 10) driver.set_window_size(1920, 1080) driver.get(url) try: WebDriverWait(driver, 300).until(EC.text_to_be_present_in_element((By.ID, "title-panel-second-line"), "Current view")) except TimeoutException: print("Timeout occured, could not get the SVG drawing in 600 seconds.") driver.quit() time.sleep(1) driver.execute_script("exportSvg(true);") time.sleep(1) svg = driver.find_element_by_id('panel-center') svg_file = open(output_file_path, 'w') svg_file.write(svg.get_attribute('innerHTML')) svg_file.close() driver.quit() run.info_single('\'%s\' saved successfully.' % output_file_path)
Example #28
Source File: tests.py From bioforum with MIT License | 4 votes |
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 )