我们从Python开源项目中,提取了以下28个代码示例,用于说明如何使用selenium.webdriver.common.keys.Keys.CONTROL。
def key_down(self, value, element=None): """ Sends a key press only, without releasing it. Should only be used with modifier keys (Control, Alt and Shift). :Args: - value: The modifier key to send. Values are defined in `Keys` class. - element: The element to send keys. If None, sends a key to current focused element. Example, pressing ctrl+c:: ActionsChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() """ if element: self.click(element) self._actions.append(lambda: self._driver.execute(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, { "value": self._keys_to_typing(value) })) return self
def key_up(self, value, element=None): """ Releases a modifier key. :Args: - value: The modifier key to send. Values are defined in Keys class. - element: The element to send keys. If None, sends a key to current focused element. Example, pressing ctrl+c:: ActionsChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() """ if element: self.click(element) self._actions.append(lambda: self._driver.execute(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, { "value": self._keys_to_typing(value) })) return self
def key_down(self, value, element=None): """ Sends a key press only, without releasing it. Should only be used with modifier keys (Control, Alt and Shift). :Args: - value: The modifier key to send. Values are defined in `Keys` class. - element: The element to send keys. If None, sends a key to current focused element. Example, pressing ctrl+c:: ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() """ if element: self.click(element) self._actions.append(lambda: self._driver.execute(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, { "value": self._keys_to_typing(value) })) return self
def key_up(self, value, element=None): """ Releases a modifier key. :Args: - value: The modifier key to send. Values are defined in Keys class. - element: The element to send keys. If None, sends a key to current focused element. Example, pressing ctrl+c:: ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() """ if element: self.click(element) self._actions.append(lambda: self._driver.execute(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, { "value": self._keys_to_typing(value) })) return self
def test_share_button(self): with self.running_container(): self.open_application_settings() self.click_first_element_located(By.ID, "share-button") self.click_first_element_located(By.ID, "cp-clipboard-button") # Now the share url should be in the clipboard input_element = self.driver.find_element_by_id("shared-url") # Clear the input element and paste what is in the clipboard in # order to retrieve it (lacking better way to retrieve the clipboard # value) input_element.clear() input_element.send_keys(Keys.CONTROL, 'v') clipboard_value = input_element.get_attribute("value") # Go to the shared url self.driver.get(clipboard_value) self.wait_until_presence_of_element_located(By.ID, "noVNC_screen") # Go back to simphony-remote self.driver.back() self.wait_until_application_list_loaded()
def Click(cls): log.step_normal("Element [%s]: Click()" % (cls.__name__)) cls.__wait() elements = env.threadlocal.BROWSER.find_elements(cls.by, cls.value) action = webdriver.ActionChains(env.threadlocal.BROWSER) action.click(elements[cls.index]) action.perform() #======================================================================= # action = webdriver.ActionChains(env.threadlocal.BROWSER) # action.key_up(Keys.CONTROL, elements[cls.index]) # action.perform() # # action.click(elements[cls.index]) # action.perform() #======================================================================= cls.__clearup()
def repost(browser): #'4136242172004022', idSet = ['4136242033629515', '4137137030367692'] while 1: i = 0 while i < 300: for id in idSet: i = i + 1 tweet_url = "https://m.weibo.cn/compose/repost?id=%s" % (id) print(id) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't') browser.get(tweet_url) sleep(2) text = browser.find_element_by_tag_name('textarea') text.send_keys('????') send = browser.find_element_by_class_name('m-send-btn') send.click() sleep(5) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w') sleep(1) print(i) sleep(4*60*60)
def repost(browser): idSet = ['4136242172004022', '4136242033629515'] i = 0 while i < 200: for id in idSet: i = i + 1 tweet_url = "https://m.weibo.cn/compose/repost?id=%s" % (id) print(id) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't') sleep(1) # browser.get(tweet_url) # text = browser.find_element_by_tag_name('textarea') text.send_keys('????') # sleep(5) # send = browser.find_element_by_class_name('m-checkbox') # send.click() sleep(1) send = browser.find_element_by_class_name('m-send-btn') send.click() sleep(5) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w') sleep(1) print(i)
def onFail(self, by, value, message, text): if message: message = message + ". " else: message = "" if text: text = ":" + text else: text = "" self.fail("Failed: {0}{1} {2}".format(message, self.describeElement(by, value), text)) #def clearKeys(self): # return [ Keys.CONTROL+"a", Keys.DELETE ]
def searchvm(self,skey,svalue): '''skey?????????????????ip???????????????? svalue ??????????''' self.Cloud_client_browser = self.driver Cloud_browser_main_map=Main_Browser_UIMap(self.Cloud_client_browser) self.Cloud_browser_main_map=Cloud_browser_main_map Cloud_browser_main_map.get_menu('server').click() Cloud_server_map=self.Cloud_server_map Cloud_server_map.get_select(skey,name='condition') Cloud_server_map.getelement(name=Cloud_server_map.searchname).send_keys(svalue) Cloud_server_map.getelement('//*[@id="product-page"]/div[3]/table/tbody/tr[1]/td[2]/a/span').send_keys(Keys.CONTROL,Keys.HOME) Cloud_server_map.getelement(Cloud_server_map.search_btn).click() if skey=='??????': text=Cloud_server_map.getelement('//*[@id="product-page"]/div[3]/table/tbody/tr[1]/td[2]/a/span').text print text assert svalue in text if skey=='ip': text=Cloud_server_map.getelement('//*[@id="product-page"]/div[3]/table/tbody/tr[1]/td[6]').text print text assert svalue in text if skey=='?????': text=Cloud_server_map.getelement('//*[@id="product-page"]/div[3]/table/tbody/tr[1]/td[5]').text print text assert svalue in text if skey=='???': text=Cloud_server_map.getelement('//*[@id="product-page"]/div[3]/table/tbody/tr[1]/td[3]').text print text assert svalue in text if skey=='?????': text=Cloud_server_map.getelement('//*[@id="product-page"]/div[2]/table/tbody/tr/td[4]').text print text assert svalue in text
def click(self, *modifiers): """ Clicks the element, optionally while pressing the given modifier keys. Note that support for holding a modifier key is currently experimental, and may not work at all. :param modifiers: modifier keys to press while clicking :Example: Click an element browser.element(name='new_user_button').click() :Example: Click an element with shift key pressed from selenium.webdriver.common.keys import Keys browser.element(name='new_user_button').click(Keys.SHIFT) :Example: Click an element with several modifier keys pressed from selenium.webdriver.common.keys import Keys browser.element(name='new_user_button').click(Keys.SHIFT, Keys.CONTROL) """ def method(): if modifiers: action = ActionChains(self.driver) for mod in modifiers: action.key_down(mod) action.click(self.el) for mod in modifiers: action.key_up(mod) action.perform() else: self.el.click() self._element_call(method, self.wait_for_enabled) self.browser.after_hooks.run()
def open_tab(self, url): """ Opens a new tab and switches focus to it. NB: Currently not used because send_keys on the driver doesn't work on OSX for Chrome (at least, might be others). """ orig_handles = self.driver.window_handles if mozinfo.os == "mac": self.driver.find_element_by_tag_name( 'body').send_keys(Keys.COMMAND + "t") else: self.driver.find_element_by_tag_name( 'body').send_keys(Keys.CONTROL + "t") time.sleep(0.25) new_handles = set(self.driver.window_handles) - orig_handles new_handle = list(new_handles)[0] self.driver.switch_to_window(new_handle) self.driver.get(url) # On Fx at least the handle can change after you load content. new_handles = set(self.driver.window_handles) - orig_handles new_handle = list(new_handles)[0] self.tabs.append(new_handle)
def open_urls(self, urls, tab_limit=MAX_TABS): """ This works at least on Chrome across platforms. """ # First setup a document with the target URLs. link_doc = 'data:text/html,' link_doc += '<html><head><title>Links!</title></head><body>' id = 0 for url in urls: link_doc += '<a id="%d" href="%s">%d: %s</a><br>' % ( id, url, id, url) id += 1 link_doc += '</body><html>' self.driver.get(link_doc) # Now open each document in a new tab by ctrl+shift clicking the # anchor. for tag in self.driver.find_elements_by_tag_name("a"): action = ActionChains(self.driver) if mozinfo.os == "mac": ctrl_key = Keys.COMMAND else: ctrl_key = Keys.CONTROL action.key_down(ctrl_key).key_down(Keys.SHIFT).click( tag).key_up(Keys.SHIFT).key_up(ctrl_key).perform() time.sleep(self.per_tab_pause) time.sleep(self.settle_wait_time) self.stats.print_stats()
def open_link_in_new_tab(self, image_name, check=True): """Step to open link of image info in new tab. Args: image_name (str): image name """ main_page = self._page_images() main_page.table_images.row(name=image_name).wait_for_presence() link_to_click = main_page.table_images.row(name=image_name).webdriver link_to_click.find_element_by_partial_link_text(image_name).send_keys( Keys.CONTROL + Keys.RETURN)
def switch_to_new_tab(self, check=True): """Step to switch to new tab.""" main_page = self.app.page_images main_page.webdriver.find_element_by_tag_name('body').send_keys( Keys.CONTROL + Keys.TAB) page = main_page.webdriver.current_window_handle main_page.webdriver.switch_to_window(page)
def check_page_is_available(self, image_name, check=True): """Step to check page is available and then close it. Args: image_name: image name """ main_page = self.app.page_images assert_that(main_page, is_not(None)) image_page = self.app.page_image image_page.image_info_main.wait_for_presence() assert_that(image_page.label_name.value, equal_to(image_name)) # close current page main_page.webdriver.find_element_by_tag_name('body').send_keys( Keys.CONTROL + 'w')
def Refresh(cls, times=4):#?? log.step_normal("Element [%s]: Browser Refresh" % (cls.__name__,)) for i in range(times): action = webdriver.ActionChains(env.threadlocal.BROWSER) action.key_down(Keys.CONTROL).send_keys(Keys.F5).key_up(Keys.CONTROL).perform() time.sleep(5)
def comment(browser): id_set = ['4136954880155475', '4135937334320864'] comment_set = [' ????????', ' ????????', ' ?????????', ' ?????!'] while 1: i = 0 j = 0 with open("poem2", 'r') as file: while i < 30: for id in id_set: i = i + 1 tweet_url = "https://m.weibo.cn/compose/comment?id=%s" % id print(id) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't') browser.get(tweet_url) sleep(5) # text = browser.find_element_by_tag_name('textarea') line = file.readline().strip('\n') if not line: break text.send_keys(comment_set[j]) text.send_keys("?????????") text.send_keys(line) print(file.readline()) j = j + 1 if j == 4: j = 0 sleep(2) send = browser.find_element_by_class_name('m-send-btn') send.click() browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w') sleep(1) print(i) sleep(4*60*60)
def Change(self,name): #Cloud_client_browser = self.driver self.admin_cloud_login(username='admin') time.sleep(1) Main_Browser_UIMap(self.driver).get_menu('change').click() Change_map=Change_UIMap(self.driver) time.sleep(3) totalRows=utils_misc.getlist_count(self.driver, '//*[@id="message_content"]/div/div/table/tbody/tr') print totalRows index=utils_misc.getindex(self.driver, totalRows, name, '//*[@id="message_content"]/div/div/table/tbody/tr[', ']/td[2]') time.sleep(1) print index utils_misc.get_xpath_text(self.driver, index, '//*[@id="message_content"]/div/div/table/tbody/tr[', ']/td[7]/a').click() time.sleep(1) Change_map.getelement('//*[@id="checkAllImage"]').click() Change_map.getelement('//a[@data-target="#image-div"]').click() #self.driver.execute_script("arguments[0].scrollIntoView();", Change_map.getelement('//*[@id="checkAllFlavor"]')) time.sleep(1) Change_map.getelement('//*[@id="checkAllFlavor"]').click() Change_map.getelement('//a[@data-target="#flavor-div"]').click() time.sleep(1) #self.driver.execute_script("arguments[0].scrollIntoView();", Change_map.getelement('//*[@id="checkAllNetwork"]')) Change_map.getelement('//*[@id="checkAllNetwork"]').click() Change_map.getelement('//a[@data-target="#network-div"]').click() #self.driver.execute_script("arguments[0].scrollIntoView();", Change_map.getelement('(//*[@id="checkAllHostInVp"])[1]')) time.sleep(1) #self.driver.execute_script("arguments[0].scrollIntoView();", Change_map.getelement('(//*[@id="checkAllHostInVp"])[2]')) #self.driver.execute_script("arguments[0].scrollIntoView();", Change_map.getelement('//*[@id="checkAllSt"]')) time.sleep(1) if utils_misc.isElementExist(self.driver, '(//*[@id="checkAllHostInVp"])[1]'): Change_map.getelement('(//*[@id="checkAllHostInVp"])[1]').click() time.sleep(1) #Change_map.getelement('//a[@data-target="#pool-div"]').click() #js = "window.scrollTo(0,document.body.scrollHeight)" #self.driver.execute_script(js) Change_map.getelement('//a[@data-target="#pool-div"]').send_keys(Keys.CONTROL,Keys.END) time.sleep(1) if utils_misc.isElementExist(self.driver, '(//*[@id="checkAllHostInVp"])[2]'): Change_map.getelement('(//*[@id="checkAllHostInVp"])[2]').click() #Change_map.getelement('//a[@data-target="#pool-div"]').click() if utils_misc.isElementExist(self.driver, '//*[@id="checkAllUnallocated"]'): Change_map.getelement('//*[@id="checkAllUnallocated"]').click() Change_map.getelement('//a[@data-target="#pool-div"]').click() Change_map.getelement('//*[@id="checkAllSt"]').click() Change_map.getelement('//a[@data-target="#st-div"]').click() Change_map.getelement('//a[@data-target="#st-div"]').send_keys(Keys.CONTROL,Keys.HOME) time.sleep(2) # js = "window.scrollTo(0,0)" #self.driver.execute_script(js) #self.driver.execute_script("arguments[0].scrollIntoView();", Change_map.getelement('//*[@id="accept-button"]')) Change_map.getelement('//*[@id="accept-button"]').click() time.sleep(10) Change_map.getelement('//*[@id="product-page"]/div[1]/li/a').click() utils_misc.get_xpath_text(self.driver, index, '//*[@id="message_content"]/div/div/table/tbody/tr[', ']/td[1]/input').click() Change_map.getelement('//*[@id="id_processed"]').click()
def test_pruebas_ini_sesion(self): driver = self.driver driver.get(self.base_url + "/#/VLogin") actions = ActionChains(self.driver) alert = Alert(self.driver) ######################## Contrasenha Invalida #################################################### driver.find_element_by_id("fLogin_usuario").clear() driver.find_element_by_id("fLogin_usuario").send_keys("Test Usuario") driver.find_element_by_id("fLogin_clave").clear() driver.find_element_by_id("fLogin_clave").send_keys("bbbbbbbb") driver.find_element_by_id("conectate").click() time.sleep(0.5) alert.accept() time.sleep(.5) actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) ######################## Usuario no Existente #################################################### driver.find_element_by_id("fLogin_usuario").clear() driver.find_element_by_id("fLogin_usuario").send_keys("UsuarioNoExiste") driver.find_element_by_id("fLogin_clave").clear() driver.find_element_by_id("fLogin_clave").send_keys("aaaaaaaa") driver.find_element_by_id("conectate").click() time.sleep(0.5) alert.accept() time.sleep(.5) actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) ######################## Usuario Vacio #################################################### driver.find_element_by_id("fLogin_clave").clear() driver.find_element_by_id("fLogin_clave").send_keys("aaaaaaaa") driver.find_element_by_id("conectate").click() actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) ######################## Clave Vacia #################################################### driver.find_element_by_id("fLogin_usuario").clear() driver.find_element_by_id("fLogin_usuario").send_keys("Test Usuario") driver.find_element_by_id("conectate").click() actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) ######################## Todo Vacio #################################################### driver.find_element_by_id("conectate").click()
def test_3(self): driver = self.driver driver.get(self.base_url + "/#/VLogin") actions = ActionChains(self.driver) driver.find_element_by_id("fLogin_usuario").clear() driver.find_element_by_id("fLogin_usuario").send_keys("Usuario") driver.find_element_by_id("fLogin_clave").clear() driver.find_element_by_id("fLogin_clave").send_keys("aaaaaaaa") driver.find_element_by_id("conectate").click() driver.find_element_by_xpath("//a[@ng-show='idUsuario']").click() driver.find_element_by_xpath("(//img[@alt='chat'])[1]").click() driver.find_element_by_id("fChat_texto").clear() driver.find_element_by_id("fChat_texto").send_keys("Probando") time.sleep(1) driver.find_element_by_id("btnHilos").click() time.sleep(1) actions.send_keys(Keys.ESCAPE) actions.perform() time.sleep(.5) driver.find_element_by_xpath("//span[@ng-bind='idUsuario']").click() time.sleep(.5) driver.find_element_by_xpath("//a[@ng-click='ASalir(idUsuario)']").click() time.sleep(.5) actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) driver.get(self.base_url + "/#/VLogin") driver.find_element_by_id("fLogin_usuario").clear() driver.find_element_by_id("fLogin_usuario").send_keys("Usuario1") driver.find_element_by_id("fLogin_clave").clear() driver.find_element_by_id("fLogin_clave").send_keys("aaaaaaaa") driver.find_element_by_id("conectate").click() driver.find_element_by_xpath("//a[@ng-show='idUsuario']").click() driver.find_element_by_xpath("(//img[@alt='chat'])[1]").click() driver.find_element_by_id("fChat_texto").clear() driver.find_element_by_id("fChat_texto").send_keys("Prueba aceptada") time.sleep(1) driver.find_element_by_id("btnHilos").click() time.sleep(1) actions.send_keys(Keys.ESCAPE) actions.perform() time.sleep(.5) driver.find_element_by_xpath("//span[@ng-bind='idUsuario']").click() time.sleep(.5) driver.find_element_by_xpath("//a[@ng-click='ASalir(idUsuario)']").click() time.sleep(.5)
def test_3(self): driver = self.driver driver.get(self.base_url + "/#/VLogin") actions = ActionChains(self.driver) alert = Alert(self.driver) driver.find_element_by_id("fLogin_usuario").clear() driver.find_element_by_id("fLogin_usuario").send_keys("Usuario") driver.find_element_by_id("fLogin_clave").clear() driver.find_element_by_id("fLogin_clave").send_keys("aaaaaaaa") driver.find_element_by_id("conectate").click() time.sleep(1) driver.find_element_by_xpath("//a[@ng-show='idUsuario']").click() time.sleep(1) driver.find_element_by_xpath(".//*[@id='invisible_interno']/div/div[2]/div[2]").click() driver.find_element_by_xpath("//input[@placeholder='Buscar amigos']").clear() driver.find_element_by_xpath("//input[@placeholder='Buscar amigos']").send_keys('Usuario3') driver.find_element_by_id("btnHilos").click() driver.find_element_by_id("config").click() actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) driver.find_element_by_xpath("//a[contains(@ng-click,'VGrupo2')]").click() actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) driver.find_element_by_xpath("//input[@placeholder='Buscar amigos']").send_keys('Usuario3') driver.find_element_by_id("btnHilos").click() driver.find_element_by_id("config").click() actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) driver.get(self.base_url + "/#/VAdminContactos/Usuario") driver.find_element_by_xpath("(//a[contains(@ng-click,'AElimContacto1')])[2]").click() time.sleep(0.5) alert.accept() time.sleep(.5) actions.send_keys(Keys.CONTROL) actions.send_keys('r') actions.perform() time.sleep(.5) driver.find_element_by_xpath("//span[@ng-bind='idUsuario']").click() time.sleep(.5) driver.find_element_by_xpath("//a[@ng-click='ASalir(idUsuario)']").click() time.sleep(.5)
def action(action_name): global page_location if action_name == "click": links = get_links() try: if len(links) > 0: for link in links: print link.text links[0].click() except: print ":speak:Can't open the link." elif action_name == "search": text = get_text("Ready") elem = browser.find_element_by_name('q') # Find the search box elem.clear() elem.send_keys('{}'.format(text) + Keys.RETURN) elif action_name == "back": browser.execute_script("window.history.go(-1)") elif action_name == "top": browser.execute_script("window.scrollTo(0, document.body.scrollHeight);") elif action_name == "down": browser.execute_script("window.scrollBy(0, 400);") elif action_name == "new tab": browser.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't') browser.get("http://www.google.com") browser.switch_to_window(main_window) elif action_name == "close tab": browser.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 'w') browser.switch_to_window(main_window) elif action_name == "switch": browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.SHIFT + Keys.TAB) browser.switch_to_window(main_window) elif action_name == "next": try: browser.find_element_by_link_text('Next').click() except: print ":speak:I couldn't find a next link."
def get_multitab(self): """Open two tab, use one to load a background site and the other to load the real site.""" PAUSE_BETWEEN_TAB_OPENINGS = 0.5 ut.timeout(cm.HARD_VISIT_TIMEOUT) # set timeout to kill running procs # load a blank page - a page is needed to send keys to the browser self.tb_driver.get(BAREBONE_HOME_PAGE) self.sniffer.start_capture(self.pcap_path, 'tcp and not host %s and not host %s' % (VBOX_GATEWAY_IP, LOCALHOST_IP)) time.sleep(cm.PAUSE_BETWEEN_INSTANCES) try: self.tb_driver.set_page_load_timeout(cm.SOFT_VISIT_TIMEOUT) except: wl_log.info("Exception setting a timeout {}".format(self.page_url)) wl_log.info("Crawling URL: {} with {} in the background". format(self.page_url, self.bg_site)) body = self.tb_driver.find_element_by_tag_name("body") body.send_keys(Keys.CONTROL + 't') # open a new tab # now that the focus is on the address bar, load the background # site by "typing" it to the address bar and "pressing" ENTER (\n) # simulated by send_keys function body.send_keys('%s\n' % self.bg_site) # the delay between the loading of background and real sites time.sleep(PAUSE_BETWEEN_TAB_OPENINGS) body = self.tb_driver.find_element_by_tag_name("body") body.send_keys(Keys.CONTROL + 't') # open a new tab t1 = time.time() self.tb_driver.get(self.page_url) # load the real site in the 2nd tab page_load_time = time.time() - t1 wl_log.info("{} loaded in {} sec" .format(self.page_url, page_load_time)) time.sleep(cm.WAIT_IN_SITE) if self.capture_screen: self.take_screenshot() self.cleanup_visit()
def repost(browser): idSet = ['4136242172004022', '4136242033629515', '4137137030367692'] result = EC.alert_is_present()(browser) flag = 1 count = 0 total_num = 0 while 1: if result: if flag: print('????????????????') sleep(4 * 60 * 60) else: print('?????????????????') sleep(4 * 60 * 60) else: count = count + 1 sum_num = 0 print('???????%d????' % count) i = 95 print(time.strftime('?????%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) with open("poem2", 'r') as file: if i < 100: if result: break for id in idSet: if result: break i = i + 1 tweet_url = "https://m.weibo.cn/compose/repost?id=%s" % id browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't') browser.get(tweet_url) sleep(10) text = browser.find_element_by_tag_name('textarea') line = file.readline().strip('\n') if not line: break text.send_keys(line) text.send_keys('????') sleep(10) send = browser.find_element_by_class_name('m-send-btn') send.click() sleep(10) browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w') sleep(1) print(i) result = EC.alert_is_present()(browser) print(result) if result: break print('?????%d' % i) sum_num = sum_num + i total_num = total_num + sum_num print('?????????%d???????%d?????????' % (sum_num, total_num)) print(time.strftime('?????%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) sleep(4*60*60) print(time.strftime('?????%Y-%m-%d %H:%M:%S', time.localtime(time.time())))