Python selenium.webdriver.support.expected_conditions.element_to_be_clickable() Examples
The following are 30
code examples of selenium.webdriver.support.expected_conditions.element_to_be_clickable().
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: screenshot.py From AboveTustin with MIT License | 8 votes |
def loadmap(self): ''' loadmap() Creates a browser object and loads the webpage. It sets up the map to the proper zoom level. Returns the browser on success, None on fail. ''' browser = webdriver.PhantomJS(desired_capabilities={'phantomjs.page.settings.resourceTimeout': '20000'}) browser.set_window_size(abovetustin_image_width, abovetustin_image_height) print("getting web page {}".format(self.url)) browser.set_page_load_timeout(15) browser.get(self.url) # Need to wait for the page to load timeout = g_request_timeout print ("waiting for page to load...") wait = WebDriverWait(browser, timeout) element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'vrsMenu'))) self.browser = browser
Example #2
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 #3
Source File: __init__.py From bilibiliupload with MIT License | 7 votes |
def crack(self): true_image = self.get_true_image() x_offset = self.analysis(true_image) print(x_offset) track = self.get_track(x_offset) knob_element = WebDriverWait(self.driver, 50).until( EC.element_to_be_clickable((By.XPATH, r'/html/body/div[2]/div[2]/div[6]/div/div[1]/div[2]/div[2]'))) self.move_to_gap(knob_element, track) # fn = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'result0.png') # fn1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'result1.png') # time.sleep(0.02) # screen_shot = self.driver.save_screenshot(fn) # time.sleep(2) # screen_shot = self.driver.save_screenshot(fn1)
Example #4
Source File: bots.py From Dallinger with MIT License | 7 votes |
def participate(self): random.seed(self.worker_id) chatbot = random.choice(self.PERSONALITIES) WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.ID, "send-message")) ) logger.info("Entering participate method") start = time.time() while (time.time() - start) < self.TOTAL_CHAT_TIME: self.wait_to_send_message() history = self.get_chat_history() logger.info("History: %s" % history) if history and history[-1]: logger.info("Responding to: %s" % history[-1]) output = chatbot.respond(history[-1]) else: logger.info("Using random greeting.") output = random.choice(self.GREETINGS) logger.info("Output: %s" % output) self.send_message(output) self.leave_chat()
Example #5
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def go_to_workflow_flush(self): # Click in the top menu self.selenium.find_element_by_id('ontask-base-table').click() # Wait for the Full View to be clickable WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.XPATH, '//button[normalize-space() = "Flush data table"]') ) ) # Click on the flush self.selenium.find_element_by_xpath( '//button[normalize-space() = "Flush data table"]' ).click() WebDriverWait(self.selenium, 10).until( EC.presence_of_element_located( (By.XPATH, '//div[@id="modal-item"]//form') ) ) WebDriverWait(self.selenium, 10).until( ElementHasFullOpacity((By.XPATH, '//div[@id="modal-item"]')) )
Example #6
Source File: acceptance_helpers.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def wait_until_clickable(self, driver, elem_id, by=By.ID, timeout=10): """ Wait for the modal to be shown. :param driver: Selenium driver instance :type driver: selenium.webdriver.remote.webdriver.WebDriver :param elem_id: element ID :type elem_id: str :param by: What method to use to find the element. This must be one of the strings which are values of :py:class:`selenium.webdriver.common.by.By` attributes. :type by: str :param timeout: timeout in seconds :type timeout: int """ WebDriverWait(driver, timeout).until( EC.element_to_be_clickable((by, elem_id)) )
Example #7
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def go_to_scheduler(self): self.selenium.find_element_by_id('ontask-base-settings').click() WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable( (By.XPATH, self.class_and_text_xpath.format('a', 'dropdown-item', 'Scheduled operations')) )) self.selenium.find_element_by_id('ontask-base-scheduler').click() WebDriverWait(self.selenium, 10).until( EC.presence_of_element_located((By.ID, 'scheduler-index')) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) self.assertIn('Scheduled Operations', self.selenium.page_source)
Example #8
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def go_to_details(self): # Goto the details page self.selenium.find_element_by_id('ontask-base-settings').click() WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable( (By.XPATH, self.class_and_text_xpath.format('a', 'dropdown-item', 'Column operations')) )) self.selenium.find_element_by_id('ontask-base-columns').click() WebDriverWait(self.selenium, 10).until( EC.presence_of_element_located((By.ID, 'workflow-detail')) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) element = self.selenium.find_element_by_id('column-table') if element: # The table is present! self.wait_for_datatable('column-table_previous') self.assertIn('Column Operations', self.selenium.page_source)
Example #9
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def go_to_workflow_operations(self): # Goto the details page self.selenium.find_element_by_id('ontask-base-settings').click() WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable( (By.XPATH, self.class_and_text_xpath.format('a', 'dropdown-item', 'Workflow operations')) )) self.selenium.find_element_by_id('ontask-base-workflow').click() WebDriverWait(self.selenium, 10).until( EC.presence_of_element_located((By.ID, 'workflow-detail')) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) self.assertIn('js-workflow-clone', self.selenium.page_source)
Example #10
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def go_to_table(self): # Click in the top menu self.selenium.find_element_by_id('ontask-base-table').click() # Wait for the Full View to be clickable WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.LINK_TEXT, 'Full view') ) ) # Click on the full view element self.selenium.find_element_by_link_text('Full view').click() # Wait for page to refresh WebDriverWait(self.selenium, 10).until( EC.presence_of_element_located((By.ID, 'table-content')) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) element = self.selenium.find_element_by_id('table-data') if element: # The table is present! self.wait_for_datatable('table-data_previous') self.assertIn('CSV Download', self.selenium.page_source)
Example #11
Source File: __init__.py From ontask_b with MIT License | 6 votes |
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 #12
Source File: kleinanzeigen.py From ebayKleinanzeigen with Apache License 2.0 | 6 votes |
def login(config): input_email = config['glob_username'] input_pw = config['glob_password'] log.info("Login with account email: " + input_email) driver.get('https://www.ebay-kleinanzeigen.de/m-einloggen.html') WebDriverWait(driver, 6).until(EC.element_to_be_clickable((By.ID, 'gdpr-banner-accept'))).click() text_area = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.ID, 'login-email'))) text_area.send_keys(input_email) fake_wait(200) text_area = driver.find_element_by_id('login-password') text_area.send_keys(input_pw) fake_wait(200) submit_button = driver.find_element_by_id('login-submit') submit_button.click()
Example #13
Source File: WebRunner.py From PyWebRunner with MIT License | 6 votes |
def wait_for_clickable(self, selector='', **kwargs): ''' Wait for an element to be clickable. 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.element_to_be_clickable((by, selector)), **kwargs)
Example #14
Source File: wechat_moment.py From learn_python3_spider with MIT License | 6 votes |
def find_xiaoshuaib(self): # 获取到搜索按钮后点击 search_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/iq"))) # 等搜索建立索引再点击 time.sleep(10) search_btn.click() # 获取搜索框并输入 search_input = self.wait.until(EC.presence_of_element_located((By.ID, "com.tencent.mm:id/kh"))) search_input.send_keys("wistbean") print('搜索小帅b...') # 点击头像进入 xiaoshuaib_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/py"))) xiaoshuaib_btn.click() # 点击右上角...进入 menu_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/jy"))) menu_btn.click() # 再点击头像 icon_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/e0c"))) icon_btn.click() # 点击朋友圈 moment_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/d86"))) moment_btn.click() print('进入朋友圈...')
Example #15
Source File: tntapi.py From 20up with GNU General Public License v3.0 | 6 votes |
def getNextPicture(self): """ Get the next picture to the given picture. """ try: next = WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.ID, INFOS['next']))) try: self.driver.execute_script("document.getElementById('" + INFOS['next'] + "').focus();") except: pass finally: next.click() except: try: next = WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, INFOS['next3']))) next.click() except: pass
Example #16
Source File: client.py From linkedin-jobs-scraper with MIT License | 6 votes |
def login(self): """login to linkedin then wait 3 seconds for page to load""" # Enter login credentials WebDriverWait(self.driver, 120).until( EC.element_to_be_clickable( (By.ID, "session_key-login") ) ) elem = self.driver.find_element_by_id("session_key-login") elem.send_keys(self.username) elem = self.driver.find_element_by_id("session_password-login") elem.send_keys(self.password) # Enter credentials with Keys.RETURN elem.send_keys(Keys.RETURN) # Wait a few seconds for the page to load time.sleep(3)
Example #17
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def click_dropdown_option_by_number(self, dd_xpath, option_num): """Click the nth option in a dropdown menu. 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_num: position of the option in the dropdown to click :return: Nothing """ self.selenium.find_element_by_xpath(dd_xpath).click() WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable( (By.XPATH, dd_xpath + '/..//*[{0}]'.format(option_num)) )) self.selenium.find_element_by_xpath( dd_xpath + '/..//*[{0}]'.format(option_num) ).click()
Example #18
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def create_filter(self, cdesc, rule_tuples): # Make sure we are in the Filter tab self.select_filter_tab() self.create_condition_base( '//button[contains(@class, "js-filter-create")]', None, cdesc, rule_tuples) # Make sure the page refreshes and shows again the filter tab WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.ID, 'filter-set-header') ) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) )
Example #19
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def create_condition(self, cname, cdesc, rule_tuples): # Make sure we are in the Text Condition tab self.select_condition_tab() self.selenium.execute_script('window.scroll(0,0);') self.create_condition_base( '//button[contains(@class, "js-condition-create")]', cname, cdesc, rule_tuples) # Make sure the page refreshed WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.CLASS_NAME, 'js-condition-create') ) )
Example #20
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def create_attachment(self, attachment_name): # Make sure we are in the Filter tab self.select_attachment_tab() self.click_dropdown_option( '//*[@id="attachment-selector"]', attachment_name) # Make sure the page refreshes and shows again the filter tab WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.ID, 'attachments') ) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) )
Example #21
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def open_action_run(self, name, is_action_in=False): element = self.search_action(name) element.find_element_by_xpath('td[1]/div/button[2]').click() if is_action_in: self.wait_for_datatable('actioninrun-data_previous') else: # Preview button clickable WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.XPATH, '//button[contains(@class, "js-action-preview")]'), ) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) )
Example #22
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def open_condition(self, cname, xpath=None): # Select the right button element if not xpath: xpath = \ '//div[@id="condition-set"]' \ '/div/h5[contains(normalize-space(), "{0}")]' \ '/../div/button[contains(@class, "js-condition-edit")]'.format( cname ) # Wait for the element to be clickable, and click WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable((By.XPATH, xpath)) ) self.selenium.find_element_by_xpath(xpath).click() # Wait for the modal to open WebDriverWait(self.selenium, 10).until( EC.presence_of_element_located((By.ID, 'id_description_text'))) WebDriverWait(self.selenium, 10).until( ElementHasFullOpacity((By.XPATH, '//div[@id="modal-item"]')) )
Example #23
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def select_filter_tab(self): """ Assuming we are in the action edit page, click on the link to open the filter tab :return: """ WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable((By.ID, 'filter-tab')) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) self.selenium.find_element_by_id('filter-tab').click() WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.ID, 'filter-set-header') ) )
Example #24
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def select_condition_tab(self): """ Assuming we are in the action edit page, click on the link to open the condition tab :return: """ WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.ID, 'conditions-tab') ) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) self.selenium.find_element_by_id('conditions-tab').click() WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.CLASS_NAME, 'js-condition-create') ) )
Example #25
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def select_attachment_tab(self): """ Assuming we are editing an Email Report action, click on the link to open the attachment tab :return: """ WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable((By.ID, 'attachments-tab')) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) self.selenium.find_element_by_id('attachments-tab').click() WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.ID, 'attachments') ) )
Example #26
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def select_questions_condition(self, qname, cname): # Click in the pull down menu element = self.selenium.find_element_by_xpath( '//table[@id="column-selected-table"]' '//td[2][normalize-space() = "{0}"]/' '../td[5]/div/button'.format(qname)) element.click() # Click in the condition name self.selenium.find_element_by_xpath( '//table[@id="column-selected-table"]' '//td[2][normalize-space() = "{0}"]/' '../td[5]/div/div/button[normalize-space() = "{1}"]'.format( qname, cname ) ).click() WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.XPATH, '//button[contains(@class, "js-action-question-add")]') ) )
Example #27
Source File: __init__.py From ontask_b with MIT License | 6 votes |
def select_rubric_tab(self): """ Assuming we are in the action edit page, click on the link to open the rubric tab :return: """ WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.ID, 'rubric-tab') ) ) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner')) ) self.selenium.find_element_by_id('rubric-tab').click() WebDriverWait(self.selenium, 10).until( EC.element_to_be_clickable( (By.CLASS_NAME, 'js-workflow-criterion-add') ) )
Example #28
Source File: xhs_wechat.py From xhs_simple_crawler with MIT License | 6 votes |
def login(self): """ 登录微信 :return: """ # 登录按钮 login = self.wait.until(EC.presence_of_element_located((By.ID, 'com.tencent.mm:id/cjk'))) login.click() # 手机输入 phone = self.wait.until(EC.presence_of_element_located((By.ID, 'com.tencent.mm:id/h2'))) phone.set_text(USERNAME) # 下一步 next = self.wait.until(EC.element_to_be_clickable((By.ID, 'com.tencent.mm:id/adj'))) next.click() # 密码 password = self.wait.until( EC.presence_of_element_located((By.XPATH, '//*[@resource-id="com.tencent.mm:id/h2"][1]'))) password.set_text(PASSWORD) # 提交 submit = self.wait.until(EC.element_to_be_clickable((By.ID, 'com.tencent.mm:id/adj'))) submit.click()
Example #29
Source File: wait_operations.py From warriorframework with Apache License 2.0 | 6 votes |
def wait_until_element_is_clickable(self, browser_instance, locator_type, locator, timeout=5): try: WebDriverWait(browser_instance, int(timeout)).until(EC.element_to_be_clickable((BYCLASS[locator_type.strip().upper()], locator))) status = True except KeyError: print_error("The given locator_type - '{0}' does not match any of " "the accepted locator_types.".format(locator_type)) print_error("{0}, {1}, {2}, {3}, {4}, {5}, {6}, and {7} are the " "accepted locator types.".format("id", "xpath", "link" "class", "tag", "name", "css_selector", "partial_link")) status = "ERROR" except TimeoutException: print_error("Element unclickable after {0} seconds".format(timeout)) status = False except Exception as e: print_error("An Exception Ocurred: {0}".format(e)) status = "ERROR" return status
Example #30
Source File: amazon_gift_card_reload.py From debbit with MIT License | 6 votes |
def handle_anti_automation_challenge(driver, merchant): try: WebDriverWait(driver, 5).until(expected_conditions.element_to_be_clickable((By.XPATH, "//*[contains(text(),'nter the characters')]"))) if driver.find_elements_by_id('ap_password'): driver.find_element_by_id('ap_password').send_keys(merchant.psw) LOGGER.info('amazon captcha detected') input(''' Anti-automation captcha detected. Please follow these steps, future runs shouldn't need captcha input unless you set "use_cookies: no" in config.txt. 1. Open the Firefox window that debbit created. 2. Input the captcha / other anti-automation challenges. 3. You should now be on the gift card reload page 4. Click on this terminal window and hit "Enter" to continue running debbit. ''') except TimeoutException: pass