Python selenium.webdriver.common.by.By.TAG_NAME Examples
The following are 30
code examples of selenium.webdriver.common.by.By.TAG_NAME().
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.common.by.By
, or try the search function
.
Example #1
Source File: scrape_lib.py From finance-dl with GNU General Public License v2.0 | 6 votes |
def for_each_frame(self): self.driver.switch_to.default_content() seen_ids = set() def helper(nesting_level=0): def handle_frames(frames): frames = [f for f in frames if f.id not in seen_ids] seen_ids.update(f.id for f in frames) for frame in frames: self.driver.switch_to.frame(frame) yield from helper(nesting_level=nesting_level + 1) self.driver.switch_to.parent_frame() yield for element_name in ['frame', 'iframe']: try: other_frames = self.find_visible_elements( By.TAG_NAME, element_name) yield from handle_frames(other_frames) except: pass yield from helper()
Example #2
Source File: test_selenium.py From dokomoforms with GNU General Public License v3.0 | 6 votes |
def test_view_data_button(self): self.get('/') self.wait_for_element( 'tr.odd:nth-child(1) > td:nth-child(5) > a:nth-child(1)', by=By.CSS_SELECTOR ) self.click(self.drv.find_element_by_css_selector( 'tr.odd:nth-child(1) > td:nth-child(5) > a:nth-child(1)' )) self.wait_for_element('h3', by=By.TAG_NAME) self.assertEqual( self.drv.find_element_by_tag_name('h3').text, 'Survey Data' )
Example #3
Source File: test_e2e_index_mobile.py From django-baton with MIT License | 6 votes |
def test_content(self): # Wait until baton is ready wait = WebDriverWait(self.driver, 10) wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) # page title page_title = self.driver.find_element_by_css_selector( "#content h1") self.assertEqual(page_title.get_attribute('innerHTML'), 'Baton administration') self.assertEqual(page_title.is_displayed(), True) # recent actions recent_actions = self.driver.find_element_by_id('recent-actions-module') self.assertEqual(recent_actions.is_displayed(), True) modules = self.driver.find_elements_by_css_selector( "#content-main .module") self.assertEqual(len(modules), 3)
Example #4
Source File: chrome_tixcraft.py From tixcraft_bot with Apache License 2.0 | 6 votes |
def kktix_captcha_text_value(captcha_inner_div): ret = "" if captcha_inner_div is not None: try: captcha_password_text = captcha_inner_div.find_element(By.TAG_NAME, "input") if not captcha_password_text is None: ret = captcha_password_text.get_attribute('value') else: print("find captcha input field fail") except Exception as exc: print("find captcha_inner_div Exception:") #print(exc) pass return ret
Example #5
Source File: test_e2e_input_filter.py From django-baton with MIT License | 6 votes |
def test_filter(self): # Wait until baton is ready wait = WebDriverWait(self.driver, 10) wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) time.sleep(2) rows = self.driver.find_elements_by_css_selector( '#result_list tbody tr') self.assertEqual(len(rows), 3) filter_button = self.driver.find_element_by_css_selector( '.changelist-filter-toggler') filter_button.click() input = self.driver.find_element_by_css_selector( '#changelist-filter-modal input') input.send_keys('super') input.send_keys(Keys.RETURN) rows = self.driver.find_elements_by_css_selector( '#result_list tbody tr') self.assertEqual(len(rows), 2)
Example #6
Source File: webdriver.py From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License | 6 votes |
def scan_webdriver(self): self.browser.get(self.entry_url) try: WebDriverWait(self.browser, 30).until( EC.presence_of_element_located((By.TAG_NAME, "body")) ) except TimeoutException as e: messages.error(self.request, e) self.browser.delete_all_cookies() self.browser.add_cookie(self.wtm_cookie) self.browser.add_cookie(self.wtm_debug_cookie) self.browser.get(self.entry_url) for cookie in self.browser.get_cookies(): self.process_webdriver_cookie(cookie) self.browser.quit()
Example #7
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 #8
Source File: util.py From micromasters with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get(self, relative_url, ignore_errors=False): """ Tells the browser to navigate to a relative URL (e.g.: '/learners') and makes sure there were no console errors during page load. """ url = make_absolute_url(relative_url, self.live_server_url) self.driver.get(url) self.wait_until_loaded(By.TAG_NAME, 'body') if not ignore_errors: self.assert_no_console_errors() else: self.dump_console_logs()
Example #9
Source File: test_e2e_menu_mobile.py From django-baton with MIT License | 5 votes |
def test_menu(self): # Wait until baton is ready wait = WebDriverWait(self.driver, 10) wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) time.sleep(2) navbar = self.driver.find_element_by_class_name('sidebar-menu') self.assertEqual('menu-open' in self.driver.find_element_by_tag_name('body').get_attribute('class').split(), False) self.assertEqual(self.navbar_is_invisible(navbar), True) toggler = self.driver.find_element_by_css_selector(".navbar-toggler") toggler.click() self.assertEqual(self.navbar_is_visible(navbar), True) self.assertEqual('menu-open' in self.driver.find_element_by_tag_name('body').get_attribute('class').split(), True) root_voices = navbar.find_elements_by_css_selector('.depth-0 > li') close_button = self.driver.find_element_by_class_name('fa-times') close_button.click() self.assertEqual('menu-open' in self.driver.find_element_by_tag_name('body').get_attribute('class').split(), False) self.assertEqual(self.navbar_is_invisible(navbar), True) toggler.click() # system title voice self.assertEqual(root_voices[0].get_attribute('innerText'), 'SYSTEM') self.assertEqual(root_voices[0].is_displayed(), True) self.assertEqual('title' in root_voices[0].get_attribute('class').split(), True) self.assertEqual(len(root_voices), 6)
Example #10
Source File: test_e2e_index.py From django-baton with MIT License | 5 votes |
def test_footer(self): # Wait until baton is ready wait = WebDriverWait(self.driver, 10) wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) links = self.driver.find_elements_by_css_selector( "#footer .col-sm-4 p") self.assertEqual(len(links), 3) # support self.assertEqual(links[0].find_element_by_css_selector('a').get_attribute('href'), 'mailto:mail@otto.to.it') self.assertEqual(links[0].get_attribute('innerText').strip(), 'Support') # copyright self.assertEqual(links[1].get_attribute('innerText').strip(), 'copyright © 2020 Otto srl') # powered by self.assertEqual(links[2].get_attribute('innerText').strip(), 'Baton Test App\nDeveloped by Otto srl')
Example #11
Source File: test_e2e_index.py From django-baton with MIT License | 5 votes |
def test_navbar(self): # Wait until baton is ready wait = WebDriverWait(self.driver, 10) wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) # site title site_name = self.driver.find_element_by_css_selector("#site-name a") self.assertEqual( site_name.get_attribute('innerHTML'), 'Baton Test App') # user dropdown user_dropdown_el = self.driver.find_element_by_css_selector( "#user-tools .dropdown-toggle") user_dropdown_text = user_dropdown_el.text self.assertEqual(user_dropdown_text, 'admin') self.assertEqual(user_dropdown_el.is_displayed(), True) # user dropdown menu user_dropdown_menu = self.driver.find_elements_by_css_selector( "#user-tools .dropdown-menu a") self.assertEqual(len(user_dropdown_menu), 3) self.assertEqual(user_dropdown_menu[0].get_attribute('innerHTML'), 'View site') self.assertEqual(user_dropdown_menu[1].get_attribute('innerHTML'), 'Change password') self.assertEqual(user_dropdown_menu[2].get_attribute('innerHTML'), 'Log out')
Example #12
Source File: test_e2e_index_mobile.py From django-baton with MIT License | 5 votes |
def test_footer(self): # Wait until baton is ready wait = WebDriverWait(self.driver, 10) wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) links = self.driver.find_elements_by_css_selector( "#footer .col-sm-4 p") self.assertEqual(len(links), 3) # support self.assertEqual(links[0].find_element_by_css_selector('a').get_attribute('href'), 'mailto:mail@otto.to.it') self.assertEqual(links[0].get_attribute('innerText').strip(), 'Support') # copyright self.assertEqual(links[1].get_attribute('innerText').strip(), 'copyright © 2020 Otto srl') # powered by self.assertEqual(links[2].get_attribute('innerText').strip(), 'Baton Test App\nDeveloped by Otto srl')
Example #13
Source File: test_finds.py From webium with Apache License 2.0 | 5 votes |
def test_dynamic_find(self): paragraphs = Finds(by=By.TAG_NAME, value='p', context=self.page.physical_container) eq_(paragraphs[1].text, 'after pre')
Example #14
Source File: formgrade_utils.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _wait_for_tag(browser, tag, time=10): return WebDriverWait(browser, time).until( EC.presence_of_element_located((By.TAG_NAME, tag)) )
Example #15
Source File: test_e2e_index_mobile.py From django-baton with MIT License | 5 votes |
def test_navbar(self): # Wait until baton is ready wait = WebDriverWait(self.driver, 10) wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready")) time.sleep(1) # toggler toggler = self.driver.find_element_by_css_selector(".navbar-toggler") self.assertEqual(toggler.is_displayed(), True) # site title site_name = self.driver.find_element_by_css_selector("#site-name a") self.assertEqual( site_name.get_attribute('innerHTML'), 'Baton Test App') # user dropdown user_dropdown_el = self.driver.find_element_by_css_selector( "#user-tools .dropdown-toggle") user_dropdown_text = user_dropdown_el.text self.assertEqual(user_dropdown_text, 'admin') self.assertEqual(user_dropdown_el.is_displayed(), True) # user dropdown menu user_dropdown_menu = self.driver.find_elements_by_css_selector( "#user-tools .dropdown-menu a") self.assertEqual(len(user_dropdown_menu), 3) self.assertEqual(user_dropdown_menu[0].get_attribute('innerHTML'), 'View site') self.assertEqual(user_dropdown_menu[1].get_attribute('innerHTML'), 'Change password') self.assertEqual(user_dropdown_menu[2].get_attribute('innerHTML'), 'Log out')
Example #16
Source File: test_utils.py From sos-notebook with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _wait_for_multiple(driver, locator_type, locator, timeout, wait_for_n, visible=False): """Waits until `wait_for_n` matching elements to be present (or visible). Returns located elements when found. Args: driver: Selenium web driver instance locator_type: type of locator (e.g. By.CSS_SELECTOR or By.TAG_NAME) locator: name of tag, class, etc. to wait for timeout: how long to wait for presence/visibility of element wait_for_n: wait until this number of matching elements are present/visible visible: if True, require that elements are not only present, but visible """ wait = WebDriverWait(driver, timeout) def multiple_found(driver): elements = driver.find_elements(locator_type, locator) if visible: elements = [e for e in elements if e.is_displayed()] if len(elements) < wait_for_n: return False return elements return wait.until(multiple_found)
Example #17
Source File: test_utils.py From sos-notebook with BSD 3-Clause "New" or "Revised" License | 5 votes |
def wait_for_tag(driver, tag, timeout=10, visible=False, single=False, wait_for_n=1): if wait_for_n > 1: return _wait_for_multiple(driver, By.TAG_NAME, tag, timeout, wait_for_n, visible) return _wait_for(driver, By.TAG_NAME, tag, timeout, visible, single)
Example #18
Source File: page.py From PyPOM with Mozilla Public License 2.0 | 5 votes |
def loaded(self): """Loaded state of the page. By default the driver will try to wait for any page loads to be complete, however it's not uncommon for it to return early. To address this you can override :py:attr:`loaded` to return ``True`` when the page has finished loading. :return: ``True`` if page is loaded, else ``False``. :rtype: bool Usage (Selenium):: from pypom import Page from selenium.webdriver.common.by import By class Mozilla(Page): @property def loaded(self): body = self.find_element(By.TAG_NAME, 'body') return 'loaded' in body.get_attribute('class') Usage (Splinter):: from pypom import Page class Mozilla(Page): def loaded(self): body = self.find_element('tag', 'body') return 'loaded' in body['class'] Examples:: # wait for the seed_url value to be in the current URL self.seed_url in self.selenium.current_url """ return True
Example #19
Source File: core.py From brutemap with GNU General Public License v3.0 | 5 votes |
def getFormElements(): """ Mendapatkan daftar ``form`` element, dari halaman situs. """ elems = waitingResult(visibility_of_all_elements_located, By.TAG_NAME, "form") or [] return elems
Example #20
Source File: base.py From django-bootstrap-modal-forms with MIT License | 5 votes |
def wait_for(self, class_name=None, element_id=None, tag=None, xpath=None): return WebDriverWait(self.browser, 20).until( expected_conditions.element_to_be_clickable ((By.ID, element_id) if element_id else (By.CLASS_NAME, class_name) if class_name else (By.TAG_NAME, tag) if tag else (By.XPATH, xpath)) )
Example #21
Source File: conftest.py From vue.py with MIT License | 5 votes |
def element_with_tag_name_present(self, tag, timeout=DEFAULT_TIMEOUT): return WebDriverWait(self.driver, timeout).until( ec.presence_of_element_located((By.TAG_NAME, tag)) )
Example #22
Source File: TraTicketBooker.py From TRA-Ticket-Booker with GNU General Public License v3.0 | 5 votes |
def connect_to_webpage(self): url_target_sg = 'http://railway1.hinet.net/csearch.htm' url_target_gb = 'http://railway.hinet.net/ctkind2.htm' self.driver.delete_all_cookies() wait = WebDriverWait(self.driver, timeout=6) try: # Booking Single Ticket. if self.book_type == 1: self.driver.get(url_target_sg) wait.until( EC.presence_of_element_located( (By.TAG_NAME, 'button') ) ) # Booking Go-Back Ticket. elif self.book_type == 2: self.driver.get(url_target_gb) wait.until( EC.presence_of_element_located( (By.TAG_NAME, 'button') ) ) except: self.label_show_result.setText( '【連線逾時或是網路不穩定】\n' + '【請檢查網路環境以及是否為尖峰時段。】' )
Example #23
Source File: webelement.py From python-client with Apache License 2.0 | 5 votes |
def find_element(self, by: str = By.ID, value: Union[str, Dict] = None) -> T: """Find an element given a By strategy and locator Override for Appium Prefer the find_element_by_* methods when possible. Args: by: The strategy value: The locator Usage: element = element.find_element(By.ID, 'foo') Returns: `appium.webdriver.webelement.WebElement` """ # TODO: If we need, we should enable below converter for Web context # if self._w3c: # if by == By.ID: # by = By.CSS_SELECTOR # value = '[id="%s"]' % value # elif by == By.TAG_NAME: # by = By.CSS_SELECTOR # elif by == By.CLASS_NAME: # by = By.CSS_SELECTOR # value = ".%s" % value # elif by == By.NAME: # by = By.CSS_SELECTOR # value = '[name="%s"]' % value return self._execute(RemoteCommand.FIND_CHILD_ELEMENT, {"using": by, "value": value})['value']
Example #24
Source File: webelement.py From python-client with Apache License 2.0 | 5 votes |
def find_elements(self, by: str = By.ID, value: Union[str, Dict] = None) -> List[T]: """Find elements given a By strategy and locator Override for Appium Prefer the find_elements_by_* methods when possible. Args: by: The strategy value: The locator Usage: element = element.find_elements(By.CLASS_NAME, 'foo') Returns: :obj:`list` of :obj:`appium.webdriver.webelement.WebElement` """ # TODO: If we need, we should enable below converter for Web context # if self._w3c: # if by == By.ID: # by = By.CSS_SELECTOR # value = '[id="%s"]' % value # elif by == By.TAG_NAME: # by = By.CSS_SELECTOR # elif by == By.CLASS_NAME: # by = By.CSS_SELECTOR # value = ".%s" % value # elif by == By.NAME: # by = By.CSS_SELECTOR # value = '[name="%s"]' % value return self._execute(RemoteCommand.FIND_CHILD_ELEMENTS, {"using": by, "value": value})['value']
Example #25
Source File: webdriver.py From python-client with Apache License 2.0 | 5 votes |
def find_element(self, by: str = By.ID, value: Union[str, Dict] = None) -> MobileWebElement: """'Private' method used by the find_element_by_* methods. Override for Appium Usage: Use the corresponding find_element_by_* instead of this. Returns: `appium.webdriver.webelement.WebElement`: The found element """ # TODO: If we need, we should enable below converter for Web context # if self.w3c: # if by == By.ID: # by = By.CSS_SELECTOR # value = '[id="%s"]' % value # elif by == By.TAG_NAME: # by = By.CSS_SELECTOR # elif by == By.CLASS_NAME: # by = By.CSS_SELECTOR # value = ".%s" % value # elif by == By.NAME: # by = By.CSS_SELECTOR # value = '[name="%s"]' % value return self.execute(RemoteCommand.FIND_ELEMENT, { 'using': by, 'value': value})['value']
Example #26
Source File: webdriver.py From python-client with Apache License 2.0 | 5 votes |
def find_elements(self, by: str = By.ID, value: Union[str, Dict] = None) -> Union[List[MobileWebElement], List]: """'Private' method used by the find_elements_by_* methods. Override for Appium Usage: Use the corresponding find_elements_by_* instead of this. Returns: :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements """ # TODO: If we need, we should enable below converter for Web context # if self.w3c: # if by == By.ID: # by = By.CSS_SELECTOR # value = '[id="%s"]' % value # elif by == By.TAG_NAME: # by = By.CSS_SELECTOR # elif by == By.CLASS_NAME: # by = By.CSS_SELECTOR # value = ".%s" % value # elif by == By.NAME: # by = By.CSS_SELECTOR # value = '[name="%s"]' % value # Return empty list if driver returns null # See https://github.com/SeleniumHQ/selenium/issues/4555 return self.execute(RemoteCommand.FIND_ELEMENTS, { 'using': by, 'value': value})['value'] or []
Example #27
Source File: Login.py From cadasta-platform with GNU Affero General Public License v3.0 | 5 votes |
def login_inactive(self, username, password): self.test.click_through(self.setup(username, password), (By.TAG_NAME, 'h1'))
Example #28
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 #29
Source File: test_selenium.py From dokomoforms with GNU General Public License v3.0 | 5 votes |
def test_single_photo_question(self): if self.browser == 'android' and self.version < StrictVersion('5.0'): # http://caniuse.com/#feat=stream self.skipTest('getUserMedia does not work in the <5 AOSP browser') survey_id = self.get_single_node_survey_id('photo') existing_submission = self.get_last_submission(survey_id) self.get('/enumerate/{}'.format(survey_id)) self.wait_for_element('navigate-right', By.CLASS_NAME) self.click(self.drv.find_element_by_class_name('navigate-right')) self.wait_for_element('video', by=By.TAG_NAME, visible=True) self.sleep(2) self.click(self.drv.find_element_by_tag_name('video')) self.sleep(2) self.click(self.drv.find_element_by_class_name('navigate-right')) self.click(self.drv.find_element_by_class_name('navigate-right')) self.click(self.drv.find_elements_by_tag_name('button')[0]) self.sleep(3) new_submission = self.get_last_submission(survey_id) self.assertIsNot(existing_submission, new_submission) answer = new_submission.answers[0] response = answer.response self.assertIsNotNone(response['response']) self.assertIs(type(response['response']), str) photo = self.session.query(Photo).filter_by(id=answer.answer).one() self.assertIsNotNone(photo)
Example #30
Source File: chrome_tixcraft.py From tixcraft_bot with Apache License 2.0 | 5 votes |
def tixcraft_ticket_main(url, is_verifyCode_editing): form_select = None try: #form_select = driver.find_element(By.TAG_NAME, 'select') form_select = driver.find_element(By.CSS_SELECTOR, '.mobile-select') if form_select is not None: try: #print("get select ticket value:" + Select(form_select).first_selected_option.text) if Select(form_select).first_selected_option.text=="0": is_verifyCode_editing = False except Exception as exc: print("query selected option fail") print(exc) pass if is_verifyCode_editing == False: ticket_number_auto_fill(url, form_select) # start to input verify code. try: #driver.execute_script("$('#TicketForm_verifyCode').focus();") driver.execute_script("document.getElementById(\"TicketForm_verifyCode\").focus();") is_verifyCode_editing = True print("goto is_verifyCode_editing== True") except Exception as exc: print(exc) pass else: #print("is_verifyCode_editing") # do nothing here. pass except Exception as exc: print("find select fail") pass return is_verifyCode_editing