我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用selenium.webdriver.common.keys.Keys.ESCAPE。
def _map_ascii_key_code_to_key(self, key_code): map = { 0: Keys.NULL, 8: Keys.BACK_SPACE, 9: Keys.TAB, 10: Keys.RETURN, 13: Keys.ENTER, 24: Keys.CANCEL, 27: Keys.ESCAPE, 32: Keys.SPACE, 42: Keys.MULTIPLY, 43: Keys.ADD, 44: Keys.SEPARATOR, 45: Keys.SUBTRACT, 56: Keys.DECIMAL, 57: Keys.DIVIDE, 59: Keys.SEMICOLON, 61: Keys.EQUALS, 127: Keys.DELETE } key = map.get(key_code) if key is None: key = chr(key_code) return key
def parseFriendPhotoPage(url): # ???? driver.get(url) # ?? ESC????????? driver.find_element_by_tag_name('body').send_keys(Keys.ESCAPE) # ?? Photo ??????? elm_li = driver.find_elements_by_css_selector("ul._69n li") # ?? list ??????? for index, li in enumerate(elm_li): # ??????????????????? elm_a = li.find_elements_by_css_selector('a._6i9') elm_a[0].click() # ????????????????????????FB ????????? # ???????????????????????????? time.sleep(3) # ?????????? elm_img = driver.find_element_by_css_selector('img.spotlight') image_src = elm_img.get_attribute("src") # ?????????????????? p = re.compile('([0-9]+[_0-9a-zA-Z]+\.(png|jpg|gif))') m = p.findall(image_src) # ??????????????? driver.find_element_by_css_selector('a._418x').click() # ???????? try: image = urlopen(image_src) f = open( os.path.join(os.getcwd(), 'downloads/friend/' + m[0][0]), 'wb' ) f.write( image.read() ) f.close() except: print("{} cant't be read".format(m[0][0]))
def parseFanGroupPhotoPage(url): # ???? driver.get(url) # ?? ESC????????? driver.find_element_by_tag_name('body').send_keys(Keys.ESCAPE) # ??????????????????????? 1 ??????? ?????? time.sleep(1) # ????? All Photos ??????? elm_div = driver.find_elements_by_css_selector("div._2eec div._2eea") # ?? list ??????? for index, div in enumerate(elm_div): # ????????? div?????????? div.click() # ????????????????????????FB ????????? # ???????????????????????????? time.sleep(3) # ?????????? elm_img = driver.find_element_by_css_selector('img.spotlight') image_src = elm_img.get_attribute("src") # ?????????????????? p = re.compile('([0-9]+[_0-9a-zA-Z]+\.(png|jpg|gif))') m = p.findall(image_src) # ??????????????? driver.find_element_by_css_selector('a._418x').click() # ???????? try: image = urlopen(image_src) f = open( os.path.join(os.getcwd(), 'downloads/fan_group/' + m[0][0]), 'wb' ) f.write( image.read() ) f.close() except: print("{} cant't be read".format(m[0][0]))
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)