我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用selenium.webdriver.common.keys.Keys.ARROW_DOWN。
def download_book(url, name): chromedriver = '/home/rajdeep1008/Desktop/chromedriver' os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.Chrome(chromedriver) driver.get(url) link = driver.find_element_by_link_text(name) actionChains = ActionChains(driver) actionChains.context_click(link) actionChains.send_keys(Keys.ARROW_DOWN) actionChains.send_keys(Keys.ARROW_DOWN) actionChains.send_keys(Keys.ARROW_DOWN) actionChains.send_keys(Keys.ARROW_DOWN) actionChains.send_keys(Keys.RETURN) actionChains.perform() while True: if not os.path.isfile('/home/rajdeep1008/Downloads/' + name + '.pdf'): time.sleep(5) else: break driver.quit() # download_book('http://it-ebooks.info/book/6719/', 'Android Studio Game Development')
def enterAndSelectFromDropdown(self, by, value, text, message = None, nth = 1, \ dropdownBy = None, dropdownValue = None): element = self.assertElementPresent(by, value, message = message) if not element: self.onFail(by, value, message, "Not found") element = self.sendKeys(by, value, text) if dropdownBy: self.assertElementPresent(dropdownBy, dropdownValue, message) description = "{0}-th from {1} dropdown".format(nth, self.describeElement(by, value)) self.log("Find " + description) for i in range(1, nth+1): element = self.sendKeys(by, value, Keys.ARROW_DOWN) element = self.sendKeys(by, value, Keys.ENTER, message = "Select " + description) return element
def scroll_and_click_by_partial_link_text(self, text, from_bottom=False): if from_bottom: # ???? self.driver.find_element_by_tag_name("body").send_keys(Keys.END) key = Keys.ARROW_UP else: # ???? self.driver.find_element_by_tag_name("body").send_keys(Keys.HOME) key = Keys.ARROW_DOWN x = 0 while 1: x += 1 if x%500 == 0: self.driver.refresh() time.sleep(2) if from_bottom: self.driver.find_element_by_tag_name("body").send_keys(Keys.END) else: self.driver.find_element_by_tag_name("body").send_keys(Keys.HOME) if x == 1501: print u"????????" + self.driver.current_url break self.driver.find_element_by_tag_name("body").send_keys(key) try: self.driver.find_element_by_partial_link_text(text).click() break except: continue
def scroll_and_click_by_xpath(self, text, from_bottom=False, refresh_if_failed=True, sleep_time=0): if from_bottom: # ???? self.driver.find_element_by_tag_name("body").send_keys(Keys.END) key = Keys.ARROW_UP else: # ???? self.driver.find_element_by_tag_name("body").send_keys(Keys.HOME) key = Keys.ARROW_DOWN time.sleep(sleep_time) x = 0 while 1: x += 1 if x%500 == 0: # ?????? if refresh_if_failed: self.driver.refresh() time.sleep(sleep_time) if from_bottom: self.driver.find_element_by_tag_name("body").send_keys(Keys.END) else: self.driver.find_element_by_tag_name("body").send_keys(Keys.HOME) time.sleep(sleep_time) if x == 1501: print u"????????" + self.driver.current_url break self.driver.find_element_by_tag_name("body").send_keys(key) try: self.driver.find_element_by_xpath(text).click() break except: # print text continue
def visit_wechat_index(self, wechatid): """ ???????????id??????? """ browser = self.browser browser.get("http://weixin.sogou.com/") print browser.title element_querybox = browser.find_element_by_name('query') element_querybox.send_keys(wechatid, Keys.ARROW_DOWN) element_search_btn = browser.find_element_by_xpath("//input[@value='????']") element_search_btn.click() time.sleep(3) print browser.title
def visit_wechat_index_keyword(self, word): """ ?????????????????? """ browser = self.browser browser.get("http://weixin.sogou.com/") print browser.title element_querybox = browser.find_element_by_name('query') element_querybox.send_keys(word, Keys.ARROW_DOWN) element_search_btn = browser.find_element_by_xpath("//input[@value='???']") element_search_btn.click() time.sleep(3) print browser.title