Python selenium.webdriver.support.expected_conditions.visibility_of_element_located() Examples

The following are 30 code examples of selenium.webdriver.support.expected_conditions.visibility_of_element_located(). 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: scrape_espncricinfo.py    From Awesome-Scripts with MIT License 7 votes vote down vote up
def get_latest_wallpapers():
    browser = webdriver.PhantomJS(PHANTOMJS_PATH, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
    today_date = time.strftime("%d+%b+%Y")  
    yesterday = datetime.now() - timedelta(days=1)
    yesterday_date = yesterday.strftime('%d+%b+%Y')
    first_page_url = 'http://www.espncricinfo.com/ci/content/image/?datefrom='+yesterday_date+'&dateupto='+today_date+';'
    browser.get(first_page_url)
    wait = WebDriverWait(browser, 10)
    wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "img-wrap")))
    time.sleep(2)
    # let's parse our html
    soup = BeautifulSoup(browser.page_source, "html.parser")
    images = soup.find_all('div', class_='picture')
    for image in images:
        url = "http://www.espncricinfo.com/" + image.find('a').get('href')
        print(url) 
Example #2
Source File: crawler_cei.py    From ir with Mozilla Public License 2.0 7 votes vote down vote up
def __login(self):
        if self.debug: self.driver.save_screenshot(self.directory + r'01.png')
        txt_login = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_txtLogin')
        txt_login.clear()
        txt_login.send_keys(os.environ['CPF'])

        time.sleep(3.0)
        txt_senha = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_txtSenha')
        txt_senha.clear()
        txt_senha.send_keys(os.environ['SENHA_CEI'])
        time.sleep(3.0)

        if self.debug: self.driver.save_screenshot(self.directory + r'02.png')

        btn_logar = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_btnLogar')
        btn_logar.click()

        try:
            WebDriverWait(self.driver, 60).until(EC.visibility_of_element_located((By.ID, 'objGrafPosiInv')))
        except Exception as ex:
            raise Exception('Nao foi possivel logar no CEI. Possivelmente usuario/senha errada ou indisponibilidade do site')

        if self.debug: self.driver.save_screenshot(self.directory + r'03.png') 
Example #3
Source File: WebRunner.py    From PyWebRunner with MIT License 7 votes vote down vote up
def wait_for_visible(self, selector='', **kwargs):
        '''
        Wait for an element to be visible.

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.visibility_of_element_located((by, selector)),
                       **kwargs) 
Example #4
Source File: __init__.py    From ontask_b with MIT License 6 votes vote down vote up
def access_workflow_from_home_page(self, wname):
        xpath = '//h5[contains(@class, "card-header") and ' \
                'normalize-space(text()) = "{0}"]'

        # Verify that this is the right page
        self.assertIn('New workflow', self.selenium.page_source)
        self.assertIn('Import workflow', self.selenium.page_source)

        WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable(
            (By.XPATH, xpath.format(wname))
        ))
        self.selenium.find_element_by_xpath(xpath.format(wname)).click()
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.ID, 'action-index'))
        )
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner'))
        ) 
Example #5
Source File: __init__.py    From ontask_b with MIT License 6 votes vote down vote up
def click_dropdown_option_and_wait(self, dd_xpath, option_name,
        wait_for=None):
        """
        Given a dropdown xpath, click to open and then click on the given option
        :param dd_xpath: xpath to locate the dropdown element (top level)
        :param option_name: name of the option in the dropdown to click
        :param wait_for: @id to wait for, or modal open if none.
        :return: Nothing
        """
        self.click_dropdown_option(dd_xpath, option_name)

        if wait_for:
            WebDriverWait(self.selenium, 10).until(
                EC.presence_of_element_located(
                    (By.ID, wait_for)
                )
            )
            WebDriverWait(self.selenium, 10).until_not(
                EC.visibility_of_element_located((By.ID, 'div-spinner'))
            )
        else:
            self.wait_for_modal_open() 
Example #6
Source File: crawler_advfn.py    From ir with Mozilla Public License 2.0 6 votes vote down vote up
def __recupera_tipo_ticker(self):
        WebDriverWait(CrawlerAdvfn.driver, 10).until(EC.visibility_of_element_located((By.ID, 'quoteElementPiece5')))
        tipo = CrawlerAdvfn.driver.find_element_by_id('quoteElementPiece5').text.lower()

        if tipo == 'futuro':
            return TipoTicker.FUTURO

        if tipo == 'opção':
            return TipoTicker.OPCAO

        if tipo == 'preferencial' or tipo == 'ordinária':
            return TipoTicker.ACAO

        if tipo == 'fundo':
            if self.__fundo_eh_fii():
                return TipoTicker.FII

            if self.__fundo_eh_etf():
                return TipoTicker.ETF

        return None 
Example #7
Source File: tv.py    From Kairos with GNU General Public License v3.0 6 votes vote down vote up
def find_element(browser, locator, locator_strategy=By.CSS_SELECTOR, except_on_timeout=True, visible=False, delay=CHECK_IF_EXISTS_TIMEOUT):
    if except_on_timeout:
        if visible:
            element = WebDriverWait(browser, delay).until(
                ec.visibility_of_element_located((locator_strategy, locator)))
        else:
            element = WebDriverWait(browser, delay).until(
                ec.presence_of_element_located((locator_strategy, locator)))
        return element
    else:
        try:
            if visible:
                element = WebDriverWait(browser, delay).until(
                    ec.visibility_of_element_located((locator_strategy, locator)))
            else:
                element = WebDriverWait(browser, delay).until(
                    ec.presence_of_element_located((locator_strategy, locator)))
            return element
        except TimeoutException as e:
            log.debug(e)
            log.debug("Check your {} locator: {}".format(locator_strategy, locator))
            # print the session_id and url in case the element is not found
            if browser is webdriver.Remote:
                # noinspection PyProtectedMember
                log.debug("In case you want to reuse session, the session_id and _url for current browser session are: {},{}".format(browser.session_id, browser.command_executor._url)) 
Example #8
Source File: __init__.py    From ontask_b with MIT License 6 votes vote down vote up
def login(self, uemail):
        self.open(reverse('accounts:login'))
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.ID, 'id_username')))
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner'))
        )
        self.selenium.find_element_by_id('id_username').send_keys(uemail)
        self.selenium.find_element_by_id('id_password').send_keys(boguspwd)
        self.selenium.find_element_by_id('submit-id-sign_in').click()
        # Wait for the user profile page
        WebDriverWait(self.selenium, 10).until(
            EC.visibility_of_element_located(
                (By.XPATH, '//div[@id="workflow-index"]')
            )
        )

        self.assertIn('reate a workflow', self.selenium.page_source) 
Example #9
Source File: tests.py    From python with Apache License 2.0 5 votes vote down vote up
def wait_until_visible(self, css_selector, timeout=10):
        """
        Block until the element described by the CSS selector is visible.
        """
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as ec
        self.wait_until(
            ec.visibility_of_element_located((By.CSS_SELECTOR, css_selector)),
            timeout
        ) 
Example #10
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def click(self, by_locator):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator)).click() 
Example #11
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def hover_to(self, by_locator):
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator))
        ActionChains(self.driver).move_to_element(element).perform() 
Example #12
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def assert_elem_text(self, by_locator, elem_text):
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator))
        assert element.text == elem_text 
Example #13
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def search_for(self, search_string):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(CommonPageLocators.SEARCH_BAR)).send_keys(search_string)
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(CommonPageLocators.SEARCH_GO_BUTTON)).click() 
Example #14
Source File: run_server_tests.py    From anvio with GNU General Public License v3.0 5 votes vote down vote up
def test05CreateNewProjectWithAllFiles(self):
        self.login()
        WebDriverWait(self.browser, 5).until(EC.visibility_of_element_located((By.XPATH, '//button[@title="upload data files"]')))

        self.browser.find_element_by_xpath('//button[@title="upload data files"]').click()
        WebDriverWait(self.browser, 5).until(EC.visibility_of_element_located((By.ID, 'uploadTitle')))
        self.browser.find_element_by_id('uploadTitle').send_keys('test_project_with_all_files')
        self.browser.find_element_by_id('uploadDescription').send_keys('description of test project')
        self.browser.find_element_by_id('treeFileSelect').send_keys(self.BASEPATH+'tree.txt')
        self.browser.find_element_by_id('fastaFileSelect').send_keys(self.BASEPATH+'fasta.fa')
        self.browser.find_element_by_id('dataFileSelect').send_keys(self.BASEPATH+'view_data.txt')
        self.browser.find_element_by_id('samplesOrderFileSelect').send_keys(self.BASEPATH+'samples-order.txt')
        self.browser.find_element_by_id('samplesInformationFileSelect').send_keys(self.BASEPATH+'samples-information.txt')
        self.browser.find_element_by_id('uploadFiles').click()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.LINK_TEXT, 'test_project_with_all_files')))
        self.assertTrue(self.browser.find_element_by_link_text('test_project_with_all_files')) 
Example #15
Source File: test_live.py    From ontask_b with MIT License 5 votes vote down vote up
def test_01_excelupload(self):
        # Login
        self.login('instructor01@bogus.com')

        # GO TO THE WORKFLOW PAGE
        self.access_workflow_from_home_page('wflow1')

        # Go to Excel upload/merge
        self.go_to_excel_upload_merge_step_1()

        # Upload file
        self.selenium.find_element_by_id("id_data_file").send_keys(
            os.path.join(settings.ONTASK_FIXTURE_DIR, 'excel_upload.xlsx')
        )
        self.selenium.find_element_by_id("id_sheet").click()
        self.selenium.find_element_by_id("id_sheet").clear()
        self.selenium.find_element_by_id("id_sheet").send_keys("results")
        self.selenium.find_element_by_name("Submit").click()
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable(
                (By.ID, 'checkAll'))
        )
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner'))
        )
        self.selenium.find_element_by_name("Submit").click()
        self.wait_for_datatable('table-data_previous')

        # The number of rows must be 29
        wflow = models.Workflow.objects.all()[0]
        self.assertEqual(wflow.nrows, 29)
        self.assertEqual(wflow.ncols, 14)

        # End of session
        self.logout() 
Example #16
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def click(self, by_locator):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator)).click() 
Example #17
Source File: base.py    From appstore with GNU Affero General Public License v3.0 5 votes vote down vote up
def wait_for(self, selector: str,
                 then: Callable[[WebElement], None]) -> Any:
        element = WebDriverWait(self.selenium, SELENIUM_WAIT_SEC).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, selector)))
        return then(element) 
Example #18
Source File: elements.py    From gigantum-client with MIT License 5 votes vote down vote up
def wait_to_appear(self, nsec: int = 20):
        """Wait until the element appears."""
        t0 = time.time()
        try:
            wait = WebDriverWait(self.driver, nsec)
            wait.until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, self.selector)))
        except Exception as e:
            tf = time.time()
            m = f'Timed out on {self.selector} after {tf-t0:.1f}sec'
            logging.error(m)
            if not str(e).strip():
                raise ValueError(m)
            else:
                raise e
        return self.find() 
Example #19
Source File: __init__.py    From ontask_b with MIT License 5 votes vote down vote up
def wait_for_datatable(self, table_id):
        # Wait for the table to be refreshed
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.ID, table_id))
        )
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner'))
        ) 
Example #20
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def assert_elem_text(self, by_locator, elem_text):
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator))
        assert element.text == elem_text 
Example #21
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def hover_to(self, by_locator):
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator))
        ActionChains(self.driver).move_to_element(element).perform() 
Example #22
Source File: wrapper.py    From QuestradeAPI_PythonWrapper with Apache License 2.0 5 votes vote down vote up
def login():
    browser = webdriver.Chrome(os.path.join(os.path.abspath(os.path.dirname(__file__)),'chromedriver.exe'))

    token = {}
    browser.get(authorization_url)
    try:
        # Wait on the login Submit button to appear
        WebDriverWait(browser, 30).until(
            EC.visibility_of_element_located((By.ID, 'ctl00_DefaultContent_btnContinue'))
        )
        
        # Find the username and password input fields
        inputElem_username = browser.find_element_by_id('ctl00_DefaultContent_txtUsername')
        inputElem_password = browser.find_element_by_id('ctl00_DefaultContent_txtPassword')
    
        # Populate the username and input fields
        inputElem_username.send_keys(username)
        inputElem_password.send_keys(password)
        
    
        # Wait on the Authorization Allow button to appear
        WebDriverWait(browser, 60).until(
            EC.visibility_of_element_located((By.ID, 'ctl00_DefaultContent_btnAllow'))
        )
    
        # Wait on the Authentication Token JSON to appear
        jsonElement = WebDriverWait(browser, 30).until(
            EC.presence_of_element_located((By.TAG_NAME, 'pre'))
        )
        
        token = json.loads(jsonElement.text)
        __store_token__(jsonElement.text)
        
        
    except TimeoutException:
        print('Time expired while attempting to login')
        
    finally:
        browser.quit()
        
        return token 
Example #23
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def search_for(self, search_string):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(CommonPageLocators.SEARCH_BAR)).send_keys(search_string)
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(CommonPageLocators.SEARCH_GO_BUTTON)).click() 
Example #24
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def assert_elem_text(self, by_locator, elem_text):
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator))
        assert element.text == elem_text 
Example #25
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def click(self, by_locator):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator)).click() 
Example #26
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def assert_elem_text(self, by_locator, elem_text):
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator))
        assert element.text == elem_text 
Example #27
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def hover_to(self, by_locator):
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator))
        ActionChains(self.driver).move_to_element(element).perform() 
Example #28
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def click(self, by_locator):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator)).click() 
Example #29
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def choose(self, drop_down_sel, value):
        ddm = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(drop_down_sel))
        ddm.find_element_by_css_selector("[value='{}']".format(value)).click() 
Example #30
Source File: page.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def send_text(self, by_locator, text):
        return WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator)).send_keys(text)