def test_student_find_the_cc_book_from_an_online_search_7742(self): """Find the Concept Coach book from an online search. Steps: Search the title of the book, with 'openstax' through a search engine Expected Result: The search returns a link to the book """ self.ps.test_updates['name'] = 'cc1.12.003' \ + inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = ['cc1', 'cc1.12', 'cc1.12.003', '7742'] self.ps.test_updates['passed'] = False # Test steps and verification assertions self.student.driver.get('https://www.google.com') self.student.page.wait_for_page_load() actions = ActionChains(self.student.driver) actions.send_keys('openstax concept coach biology') actions.send_keys(Keys.RETURN) actions.perform() self.student.wait.until( expect.visibility_of_element_located( (By.XPATH, '//a[contains(text(),"Biology with Concept Coach")]') ) ) self.student.driver.find_element( By.XPATH, '//cite[contains(text(),"https://cnx.org/")]') self.ps.test_updates['passed'] = True
def find_text(self, text): #click the 'find' button, and enter text. Not yet functional self('editor_find_button').click() alert = self.browser.switch_to_alert() chain = ActionChains(alert) chain.send_keys(text).perform() chain.send_keys(Keys.RETURN).perform() return
def test_report(self): self.browser.get(self.live_server_url + '/') # Login username = self.browser.find_element_by_id('username') username.send_keys('Jim') password = self.browser.find_element_by_id('password') # Send the wrong password password.send_keys('correcthorsebatterystaple') # Submit the form submit = self.browser.find_element_by_id('submit') submit.click() # Navigate to the sale page img = self.browser.find_element_by_xpath( '//div[@class="card small grey darken-3"][1]//img[@id="report-image"]') img.click() # Get the choose showing modal showing = self.browser.find_element_by_xpath( '//div[@class="col s6 center-align"][1]/button') showing.click() wait = WebDriverWait(self.browser, 10) element = wait.until(EC.element_to_be_clickable((By.ID, 'picker-modal'))) modal = self.browser.find_element_by_id('picker-modal') self.assertTrue(modal.is_displayed()) occ = self.browser.find_element_by_id('showing') occ.click() free_text = self.browser.find_element_by_xpath('//div[@id="sale-update"]//p').text self.assertIn('No tickets sold', free_text) self.assertIn('No tickets reserved', free_text) self.assertIn('80 tickets left', free_text) # Check selling tickets adds up properly pricing = models.InHousePricing.objects.get(id=1) member_price = pricing.member_price concession_price = pricing.concession_price public_price = pricing.public_price mat_f_price = pricing.matinee_freshers_price mat_f_nnt_price = pricing.matinee_freshers_nnt_price out = self.browser.find_element_by_id('out1').text member = self.browser.find_element_by_id('member') action = ActionChains(self.browser) action.click(on_element=member) action.send_keys('1') action.key_down(Keys.CONTROL) action.key_up(Keys.CONTROL) action.perform()
def rule_value(context, value): value_input = context.browser.find_element_by_xpath("//paper-input[@id='metricValue']") actions = ActionChains(context.browser) actions.move_to_element(value_input) actions.click() actions.send_keys(Keys.BACK_SPACE) actions.perform() actions.move_to_element(value_input) actions.click() actions.send_keys("0") actions.perform()
def create(self, tr): self.tds = tr.find_elements_by_tag_name('td') actions = ActionChains(self.driver) actions.move_to_element(self.tds[1]) actions.double_click() actions.send_keys(lorem_ipsum.words(1, False)) actions.perform() actions.move_to_element(self.tds[2]) actions.double_click() actions.perform() self.driver.select('select.htSelectEditor', unicode(self.experiment.pk)) self.driver.click('body')
def test_remove_success(self): table = self.driver.find_element_by_id('dataTable') self.create_units(table) tr = table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(3) + ')') actions = ActionChains(self.driver) actions.move_to_element(tr.find_element_by_css_selector('td:nth-child(2)')) actions.click() actions.key_down(Keys.SHIFT) actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(5) + ') td:nth-child(3)')) actions.click() actions.key_up(Keys.SHIFT) actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(4) + ') td:nth-child(3)')) actions.context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN) actions.send_keys(Keys.RETURN) actions.perform() self.assertEqual(len(self.driver.find_elements_by_css_selector('.htCore tbody tr')), 3 * 2)
def key_appears(context, key, seconds): if context.mist_config.get(key): key_name = context.mist_config.get(key) timeout = time() + int(seconds) while time() < timeout: try: for key_in_list in context.browser.find_elements_by_class_name('small-list-item'): if key_name == safe_get_element_text(key_in_list): actions = ActionChains(context.browser) actions.send_keys(Keys.ESCAPE) actions.perform() return True else: pass except: sleep(1) assert False, "Key %s did not appear after %s seconds" % (key,seconds)
def test_keys(self): self.driver.get("http://sahitest.com/demo/label.htm") ele = self.driver.find_element(By.XPATH, '/html/body/label[1]/input') ele.click() action = ActionChains(self.driver) action.send_keys("TOM") action.send_keys(Keys.SPACE) action.send_keys("AND JERRY ARE GOOD") action.send_keys(Keys.BACK_SPACE) action.perform() sleep(5)
def test_keys(self): self.driver.get("http://sahitest.com/demo/label.htm") ele_user = self.driver.find_element_by_xpath( "/html/body/label[1]/input") ele_user.click() action = ActionChains(self.driver) action.send_keys("Tom").pause(1) action.send_keys(Keys.SPACE).pause(1) action.send_keys("sd").pause(1) action.send_keys(Keys.BACK_SPACE).pause(1).perform() sleep(3)
def test_keys(self): self.driver.get("http://sahitest.com/demo/label.htm") ele = self.driver.find_element_by_xpath('/html/body/label[1]/input') ele.click() action = ActionChains(self.driver) action.send_keys("chiweilong").pause(1) action.send_keys(Keys.SPACE).pause(1) action.send_keys("hejingniang").pause(1) action.send_keys(Keys.BACK_SPACE) action.perform()
def test_back(self): self.driver.get("http://sahitest.com/demo/label.htm") element_input = self.driver.find_element_by_xpath( '/html/body/label[1]/input').click() action = ActionChains(self.driver) action.send_keys("abcdef").pause(1) action.send_keys(Keys.SPACE).pause(1) action.send_keys("lqm").pause(1) action.send_keys(Keys.BACK_SPACE).perform() sleep(5)
def web_actions(webdriver): try: actionChains = ActionChains(webdriver) actionChains.send_keys(keys.Keys.ARROW_DOWN).perform() time.sleep(1) x = 0 t = 0 while t < 6: t += 1 if x == 0: webdriver.execute_script("window.scrollTo(0, document.body.scrollHeight);") time.sleep(1) x += 1 else: webdriver.execute_script("window.scrollTo(document.body.scrollHeight, 0);") time.sleep(1) x -= 1 finally: print "finished!"
def trigger_keystrokes(browser, *keys): """ Send the keys in sequence to the browser. Handles following key combinations 1. with modifiers eg. 'control-alt-a', 'shift-c' 2. just modifiers eg. 'alt', 'esc' 3. non-modifiers eg. 'abc' Modifiers : http://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html """ for each_key_combination in keys: keys = each_key_combination.split('-') if len(keys) > 1: # key has modifiers eg. control, alt, shift modifiers_keys = [getattr(Keys, x.upper()) for x in keys[:-1]] ac = ActionChains(browser) for i in modifiers_keys: ac = ac.key_down(i) ac.send_keys(keys[-1]) for i in modifiers_keys[::-1]: ac = ac.key_up(i) ac.perform() else: # single key stroke. Check if modifier eg. "up" browser.send_keys(getattr(Keys, keys[0].upper(), keys[0]))
def test_admin_credentials(chrome_browser): chrome_browser.get('http://localhost/admin/') wait = WebDriverWait(chrome_browser, 5) l = wait.until( EC.visibility_of_element_located((By.CSS_SELECTOR, '#input-username'))) actions = ActionChains(chrome_browser) actions.move_to_element(l) actions.click(l) actions.send_keys("user") actions.perform() sleep(3) #l.send_keys("user") p = wait.until( EC.visibility_of_element_located((By.CSS_SELECTOR, '#input-password'))) p.send_keys("bitnami1") s = wait.until( EC.element_to_be_clickable((By.CSS_SELECTOR, '.btn.btn-primary'))) s.click() assert chrome_browser.title == 'Dashboard'
def test_keys(self): """模拟键盘输入,pause(1)表示延后一秒""" self.driver.get("http://sahitest.com/demo/label.htm") ele = self.driver.find_element_by_xpath("/html/body/label[1]/input") ele.click() action = ActionChains(self.driver) action.send_keys("name").pause(1) action.send_keys(Keys.SPACE).pause(1) action.send_keys("pwd").pause(1) action.send_keys(Keys.BACK_SPACE).pause(1) action.perform() time.sleep(5)
def category_selection(self): # self.driver.execute_script("window.scrollTo(0, 480)") self.driver.find_element_by_xpath(self.categories).click() element1 = self.driver.find_element_by_xpath( "//li[normalize-space()='Computers >> Desktops']") element2 = self.driver.find_element_by_xpath( "//li[normalize-space()='Computers >> Notebooks']") action = ActionChains(self.driver) action.move_to_element(element1) action.click() action.perform() time.sleep(2) action1 = ActionChains(self.driver) action1.move_to_element(element2) action1.click() action1.perform() time.sleep(2) action1.send_keys(Keys.TAB)
def select_users_with_keyboard_tab(self): self.driver.implicitly_wait(5) links = self.driver.find_elements_by_xpath(self.all_links_xpath) users_link = self.driver.find_element_by_link_text(self.lnk_Users_linktext).text header = self.driver.find_element_by_xpath(self.tittle_Admincentral_userList_screen_xpath) actions = ActionChains(self.driver) actions.move_to_element(header).click().perform() time.sleep(2) for element in range(len(links)): print(links[element].text) actions.send_keys(Keys.TAB) actions.perform() time.sleep(2) if links[element].text == users_link: actions.send_keys(Keys.ENTER) actions.perform() break print("Users link selected with keyboard ") self.logger.info("**************** Users link selected with keyboard ****************")
def test_action_chains_keys(self): self.driver.get("http://sahitest.com/demo/label.htm") input1 = self.driver.find_element(By.XPATH, '/html/body/label[1]/input') input2 = self.driver.find_element(By.XPATH, '/html/body/label[2]//input') action = ActionChains(self.driver) # input1.click() action.click(input2).pause(2) action.click(input1).pause(2) action.send_keys("username").pause(1).send_keys(Keys.SPACE).pause(1) action.send_keys("tome").pause(1).send_keys(Keys.BACK_SPACE).pause(1) action.key_down(Keys.CONTROL).send_keys("a").key_up( Keys.CONTROL).pause(1) action.key_down(Keys.CONTROL).send_keys("c").key_up( Keys.CONTROL).pause(1) # input2.click() action.key_down(Keys.CONTROL, input2).send_keys("v").key_up(Keys.CONTROL).pause(1) action.perform()
def allow_flash(driver, url): def _base_url(url): if url.find("://") == -1: url = "http://{}".format(url) urls = urlsplit(url) return "{}://{}".format(urls.scheme, urls.netloc) def _shadow_root(driver, element): return driver.execute_script("return arguments[0].shadowRoot", element) base_url = _base_url(url) driver.get("chrome://settings/content/siteDetails?site={}".format( url_quoteplus(base_url))) actions = ActionChains(driver) actions = actions.send_keys(Keys.TAB * 12) actions = actions.send_keys(Keys.SPACE) actions = actions.send_keys("a") actions = actions.send_keys(Keys.ENTER) actions.perform()
def keyboard(self): driver = webdriver.Chrome(executable_path="../Drivers/chromedriver.exe" ) # opens the chrome driver driver.maximize_window() driver.get( 'https://www.goibibo.com/flights/flights-from-mumbai/?utm_source=google&utm_medium=cpc&utm_campaign=DF-Generic-Overall-Mumbai-DT&utm_content=Book%20Flight%20Tickets&gclid=CjwKCAiAmNbwBRBOEiwAqcwwpeMi_-u8_amooZ5iWrkS7ErpwzMuPYbYNgf2f4ob1N5d9SJPFy43nRoC80YQAvD_BwE' ) # opens the browser with driver.find_element_by_id("gi_source_st").clear() driver.find_element_by_id("gi_source_st").send_keys("sathya") # to perform TAB operation act = ActionChains(driver) act.send_keys(Keys.TAB).perform() # to perform Control operation # act = ActionChains(driver) # act.send_keys(Keys.CONTROL).send_keys("a").perform() time.sleep(5) driver.quit()
def ScrollDown(self, steps): assert steps >= 0 ac = ActionChains(self.browser) for _ in range(steps): ac = ac.send_keys("j") while True: try: ac.perform() break except UnexpectedAlertPresentException: sleep(5)
def alert(msg, whatsappTab): driver.switch_to.window(whatsappTab) child_elem = driver.find_element_by_xpath("//span[@title='" + whatsapTarget + "']") parent_elem = child_elem.find_element_by_xpath('./../../../../..') parent_elem.click() time.sleep(load_time) inputField = driver.find_element_by_css_selector('div._3F6QL._2WovP') msgs = msg.split(';') inputField.send_keys(msgs[0]) for i in range(1, len(msgs)): action = ActionChains(driver) action.key_down(Keys.SHIFT) action.send_keys(Keys.ENTER) action.key_up(Keys.SHIFT) action.perform() inputField.send_keys(msgs[i]) driver.find_element_by_css_selector("button._35EW6").click()
def test_keys2(self): #ctrl+a:action.key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL) #ctrl+c:action.key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL) self.driver.get("http://sahitest.com/demo/label.htm") element_input1 = self.driver.find_element_by_xpath( '/html/body/label[1]/input') element_input2 = self.driver.find_element_by_xpath( '/html/body/label[2]/table/tbody/tr/td[2]/input') chains = ActionChains(self.driver) chains.click(element_input1) chains.send_keys("username tom").pause(1) chains.key_down(Keys.CONTROL).send_keys('a').key_up( Keys.CONTROL).pause(1) chains.key_down(Keys.CONTROL).send_keys('c').key_up( Keys.CONTROL).pause(1) chains.click(element_input2).pause(1) chains.key_down(Keys.CONTROL).send_keys('v').key_up( Keys.CONTROL).pause(1) chains.perform() sleep(1)
def test_remove_permission(self): table = self.driver.find_element_by_id('dataTable') self.create_units(table) self.driver.authorize(username=self.guest.email, password='******') self.driver.open_url(reverse('units:list', kwargs={'lab_pk': unicode(self.lab.pk)})) table = self.driver.find_element_by_id('dataTable') tr = table.find_element_by_css_selector('.htCore tbody tr:nth-child(1)') actions = ActionChains(self.driver) actions.move_to_element(tr.find_element_by_css_selector('td:nth-child(2)')) actions.click() actions.key_down(Keys.SHIFT) actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(5) + ') td:nth-child(3)')) actions.click() actions.key_up(Keys.SHIFT) actions.move_to_element(table.find_element_by_css_selector('.htCore tbody tr:nth-child(' + str(4) + ') td:nth-child(3)')) actions.context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN) actions.send_keys(Keys.RETURN) actions.perform() self.assertTrue(self.driver.is_element_present('.alert-danger')) self.assertEqual(self.driver.find_element_by_css_selector('.messages').text, 'PERMISSION DENIED')
def my_http2(url): driver = webdriver.Chrome() driver.get(url) time.sleep(5) shell = c.Dispatch('WScript.Shell') shell.SendKeys('{F12}', 0) time.sleep(4) shell.SendKeys('^+m', 0) time.sleep(2) dr1 = ActionChains(driver) driver.find_element_by_id('sb_form_q').send_keys('hu') driver.find_element_by_id('sb_form_q').send_keys(Keys.F12) driver.find_element_by_id('sb_form_q').send_keys('yang') print('Send huyangjie') time.sleep(3) dr1.send_keys(Keys.SHIFT + Keys.CONTROL + 'i') dr1.key_down(Keys.F12).pause(0.1).key_up(Keys.F12).perform() print('Send F12') time.sleep(10) driver.quit()
def visit( self, url ): ''' ''' if self.__jscoverage_loaded: self.__browser.switch_to_window( self.__browser.window_handles[0] ) else: # load JSCoverage self.__browser.get( "http://localhost:8080/jscoverage.html" ) self.__jscoverage_loaded = True # clear the jscoverage location field locationfield = self.__browser.find_element_by_id( 'location' ) locationfield.clear() # fill in url actions = ActionChains( self.__browser ) actions.click( locationfield ) actions.send_keys( url ) actions.send_keys( Keys.TAB ) actions.send_keys( Keys.TAB ) actions.send_keys( Keys.RETURN ) actions.perform() # switch to the new window self.__browser.switch_to_window( self.__browser.window_handles[-1] )
def test_keys(self): ''' 访问网址:http://sahitest.com/demo/label.htm 定位输入框e1,e2;然后输入username tom;删除一个m;最后将e1中的内容复制到e2中 知识点: 1.运用到的是selenium中的ActionChains的api; 2.send_keys来传入keys中的内容 3.keys:ctrl+点击进入查看详细内容 4.pause为暂停时间 5.ele2.send_keys(Keys.CONTROL,'v') 这是control的用法 ''' self.driver.get("http://sahitest.com/demo/label.htm") ele1 = self.driver.find_element_by_xpath("/html/body/label[1]/input") ele1.click() action = ActionChains(self.driver) action.send_keys("username").pause(1) action.send_keys(Keys.SPACE).pause(1) action.send_keys("tom").pause(1) action.send_keys(Keys.BACK_SPACE).perform() ele1.send_keys(Keys.CONTROL, 'a') sleep(1) ele1.send_keys(Keys.CONTROL, 'c') sleep(1) ele2 = self.driver.find_element_by_xpath("/html/body/label[2]/table/tbody/tr/td[2]/input") ele2.send_keys(Keys.CONTROL, 'v') sleep(1)
def select_users_with_keyboard_shiftTab(self): self.driver.implicitly_wait(5) header_elements = self.driver.find_elements_by_xpath(self.elements_header_menus_xpath) users_link = self.driver.find_element_by_link_text(self.lnk_Users_linktext).text search_input = self.driver.find_element_by_id("search_input") time.sleep(2) actions = ActionChains(self.driver) actions.move_to_element(search_input).click().perform() i = len(header_elements) - 1 while i >= 0: if i > 3: actions.key_down(Keys.SHIFT).send_keys(Keys.TAB).key_up(Keys.SHIFT) if i <= 3: print(i) time.sleep(2) if header_elements[i].text == users_link: actions.send_keys(Keys.ENTER).perform() break actions.key_down(Keys.SHIFT).send_keys(Keys.TAB).key_up(Keys.SHIFT) i -= 1 print("Users link selected with keyboard shiftTab ") self.logger.info("**************** Users link selected with keyboard shiftTab ****************")
class ActionImpl(object): def __init__(self): self.action = ActionChains(driver) def key_down(self, value, element=None): value = self.tran_value(value) self.action.key_down(value, element) def key_up(self, value, element=None): value = self.tran_value(value) self.action.key_up(value, element) def tran_value(self, value): if value == 'KEY_ENTER': value = Keys.ENTER return value def send_keys(self, *keys_to_send): self.action.send_keys(keys_to_send) def __del__(self): self.action.perform()
def addWord(): try: # method1 = browser.find_element(by=By.XPATH, value="//div[@class='funlist white1']/div[1]/a[2]/li") # # 点击进入剪裁图片界面 # method1.click() # 上传图片 input_image(path_to_image) # 添加文字 browser.find_element(by=By.XPATH, value="//img[@src='imgs/btn-wenzi-03.png']").click() # 在图片上点击 time.sleep(1) canvas = browser.find_element(by=By.CLASS_NAME, value="lower-canvas") # 添加文字框 addBox = ActionChains(browser) \ .click(canvas) # # 执行链 addBox.perform() time.sleep(1) # 双击 word = ActionChains(browser).double_click() \ .double_click() \ .perform() word = ActionChains(browser).double_click() \ .double_click() \ .perform() time.sleep(1) # 添加文字 key = ActionChains(browser) key.send_keys(Keys.NUMPAD6).perform() key.send_keys(Keys.NUMPAD6).perform() key.send_keys(Keys.NUMPAD6).perform() key.send_keys(Keys.ENTER).perform() time.sleep(1) # 变为红色字体 browser.find_element(by=By.XPATH, value="//ul[@class='color-picker-list color-picker-text white1']/li[1]").click() time.sleep(1) # 改变大小 rr = browser.find_element(by=By.XPATH, value="//input[@class='range-text-size cp abs']") rr.click() time.sleep(1) # 撤销 browser.find_element(by=By.XPATH, value="//img[@data='chexiao']").click() time.sleep(1) # 删除 browser.find_element(by=By.XPATH, value="//img[@data='delete']").click() except Exception as e: print(e) else: print(browser.current_url) # 打印所有cookies print(browser.get_cookies()) finally: # 隐形延时 browser.implicitly_wait(8)
def step_impl(context): passw=open('C:\\Projects\\first_behave\\python_behave_template-master\\pass.txt','r') actions = ActionChains(context.browser) actions.send_keys("vlad") actions.send_keys(Keys.TAB) actions.send_keys(passw.readline()) actions.send_keys(Keys.ENTER) actions.perform() try: element = WebDriverWait(context.browser, 1).until(EC.presence_of_element_located((By.CSS_SELECTOR, "body > div.ng-scope > div.page.page--with-masthead.ng-scope > div > nav > ul:nth-child(1) > li:nth-child(2) > a > div > span")) ) element.click() time.sleep(2) except Exception: print('error')
def collab_create(self, collab_name): """Create new collab. """ # Click the "Create" Header WebDriverWait(self.driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//button[@class='md-tab-header']"))).click() time.sleep(4) # Select that CRAZY 'Create new collab' field ... elem = self._wait(By.XPATH, "//input[@placeholder='Create new collab']") elem.clear() actions = ActionChains(self.driver) actions.move_to_element(elem) actions.send_keys(collab_name) actions.perform() time.sleep(2) self.click( By.XPATH, "//button[@class='md-button md-raised md-primary " "button-medium separated md-theme-default']")
def fill_codemirror_area_with(self, field_content): def find_codemirror(driver): try: driver.switch_to.default_content() driver.switch_to_frame( driver.find_element_by_tag_name("iframe")) element = driver.find_element_by_xpath( "//pre[contains(@class,'CodeMirror-line')]/../../../" "*[contains(@class,'CodeMirror-code')]") if element.is_displayed() and element.is_enabled(): return element except (NoSuchElementException, WebDriverException): return False time.sleep(1) WebDriverWait(self.driver, timeout=self.timeout, poll_frequency=0.01).\ until(find_codemirror, "Timed out waiting for codemirror " "to appear").click() time.sleep(1) action = ActionChains(self.driver) action.send_keys(field_content) action.perform()
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()
def runTests( xtkTestFile, xtkLibDir, browserString ): print 'RUNNING OFFSCREEN TESTING..' browser = getBrowser( xtkLibDir, browserString ) if not browser: return None if xtkTestFile.find( 'build' ) == -1: # this is against the DEV tree # start coverage server coverageServer( xtkLibDir ) browser.get( "http://localhost:8080/jscoverage.html" ) # now some selenium fun locationfield = browser.find_element_by_id( 'location' ) locationfield.clear() # fill in url actions = ActionChains( browser ) actions.click( locationfield ) actions.send_keys( 'testing/xtk_tests.html' ) actions.send_keys( Keys.TAB ) actions.send_keys( Keys.TAB ) actions.send_keys( Keys.RETURN ) actions.perform() browser.switch_to_window( browser.window_handles[-1] ) #browser.switch_to_frame( browser.find_elements_by_tag_name( "iframe" )[0] ) else: # we don't need os.sep here since it's a url browser.get( "file://" + xtkTestFile ) time.sleep( 3 ) result_unit = browser.execute_script( 'return window.G_testRunner.getReport(true);' ) time.sleep( 1 ) browser.switch_to_window( browser.window_handles[0] ) #browser.close() print 'RUNNING OFFSCREEN TESTING.. DONE!' # if xtkTestFile.find( 'build' ) == -1: # this is against the DEV tree # stop coverage server #coverageServer( xtkLibDir, 'stop' ) #return result #def testVisualization( xtkLibDir, browserString, againstBuild=False ): print 'RUNNING VISUAL TESTING..' #browser = getBrowser( xtkLibDir, browserString ) if not browser: return None # list of tests tests = ['test_trk.html', 'test_vtk.html', 'test_nrrd.html', 'test_vr.html', 'test_labelmap.html', 'test_shapes.html', 'test_mgh.html', 'test_mgz.html', 'test_stl.html', 'test_binstl.html'] #testURL = "file://" + xtkLibDir + "/../testing/visualization/" testURL = "testing/visualization/" baselineDir = os.path.abspath( xtkLibDir + "/../testing/visualization/baselines/" ) # we test the visualization with a fixed window size browser.set_window_size( 800, 600 ) output = '' # loop through the tests for t in tests: # open the test url = testURL + t #if againstBuild: # url += '?build' #browser.get( testURL + t ) browser.switch_to_default_content() # now some selenium fun locationfield = browser.find_element_by_id( 'location' ) locationfield.clear() # fill in url actions = ActionChains( browser ) actions.click( locationfield ) actions.send_keys( url ) actions.send_keys( Keys.TAB ) actions.send_keys( Keys.TAB ) actions.send_keys( Keys.RETURN ) actions.perform() browser.switch_to_window( browser.window_handles[-1] ) #browser.switch_to_frame( browser.find_elements_by_tag_name( "iframe" )[0] ) # wait until loading fully completed timer = 0 while not browser.execute_script( 'return test_renderer.loadingCompleted' ) and timer < 5: time.sleep( 1 ) # loading did not complete yet timer += 1 time.sleep( 1 ) # perform interaction tests, if we are using chrome if browserString == 'chrome': canvas = browser.find_element_by_tag_name( 'canvas' ) actions = ActionChains( browser ) actions.click( canvas ) # # keyboard events # # rotate for i in range( 30 ): actions.send_keys( Keys.ARROW_RIGHT ) for i in range( 30 ): actions.send_keys( Keys.ARROW_UP ) for i in range( 30 ): actions.send_keys( Keys.ARROW_LEFT ) for i in range( 30 ): actions.send_keys( Keys.ARROW_DOWN ) # zoom for i in range( 50 ): actions.key_down( Keys.LEFT_ALT ) actions.send_keys( Keys.ARROW_LEFT ) for i in range( 25 ): actions.key_down( Keys.LEFT_ALT ) actions.send_keys( Keys.ARROW_RIGHT ) # pan actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT ) actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_LEFT, Keys.ARROW_LEFT, Keys.ARROW_LEFT ) actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_UP, Keys.ARROW_UP, Keys.ARROW_UP ) actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_DOWN, Keys.ARROW_DOWN ) # # mouse # actions.click( canvas ) # rotate for i in range( 30 ): actions.click_and_hold( None ) actions.move_to_element_with_offset( canvas, 10, 0 ); actions.release( canvas ) for i in range( 30 ): actions.click_and_hold( None ) actions.move_to_element_with_offset( canvas, 0, -10 ); actions.release( canvas ) # zoom # pan for i in range( 10 ): actions.key_down( Keys.LEFT_SHIFT ) actions.click_and_hold( None ) actions.move_to_element_with_offset( canvas, 0, 10 ); actions.release( canvas ) actions.perform() # create a screenshot and save it to a temp. file testId = os.path.splitext( t )[0] testFileId = testId + '_' + browserString tmpfile = tempfile.mkstemp( suffix='.png', prefix='xtk_' + testFileId )[1] browser.save_screenshot( tmpfile ) # baseline baseline = os.path.join( baselineDir, testFileId + '_baseline.png' ) # compare temp. file vs. baseline testPassed = compareImages( tmpfile, baseline ) _now = datetime.now() timestamp = str( _now.hour ).zfill( 2 ) + ':' + str( _now.minute ).zfill( 2 ) + ':' + str( _now.second ).zfill( 2 ) + '.' + str( _now.microsecond / 1000 ).zfill( 3 ) if testPassed: testPassed = "PASSED : " + tmpfile + " : " + baseline + " : " else: testPassed = "FAILED : " + tmpfile + " : " + baseline + " : " testPassed += "\n" + timestamp + " ERROR in Visualization" + testId + '\nComparison against baseline failed.\n' output += timestamp + " Visualization" + testId + ' : ' + testPassed + '\n' browser.switch_to_window( browser.window_handles[0] ) #browser.close() _now = datetime.now() timestamp = str( _now.hour ).zfill( 2 ) + ':' + str( _now.minute ).zfill( 2 ) + ':' + str( _now.second ).zfill( 2 ) + '.' + str( _now.microsecond / 1000 ).zfill( 3 ) result = output + timestamp + ' Done\n' print output print 'RUNNING VISUAL TESTING.. DONE!' browser.switch_to_window( browser.window_handles[0] ) browser.execute_script( 'jscoverage_storeButton_click();' ) time.sleep( 1 ) browser.execute_script( 'jscoverage_recalculateSummaryTab();' ) summaryTable = browser.execute_script( 'return document.getElementById("summaryTable").innerHTML;' ) # parse the summary table data = summaryTable.replace( '\n', '' ).split( '</tr>' ) secondLine = data[1] totalNumberOfFiles = secondLine.split( '<span>' )[1].split( '</span>' )[0] totalLines = secondLine.split( '"numeric">' )[1].split( '</td>' )[0] totalTestedLines = secondLine.split( '"numeric">' )[2].split( '</td>' )[0] totalCoverage = secondLine.split( '"pct">' )[1].split( '%' )[0] covFiles = [] for i in range( 2, len( data ) - 1 ): line = data[i] fileName = line.split( '"#">' )[1].split( '</a>' )[0] lines = int( line.split( '"numeric">' )[1].split( '</td>' )[0] ) testedLines = int( line.split( '"numeric">' )[2].split( '</td>' )[0] ) untestedLines = lines - testedLines coveragePercent = line.split( '"pct">' )[1].split( '%' )[0] covFiles.append( [fileName, lines, testedLines, untestedLines, coveragePercent] ) # create XML from socket import getfqdn # WRITE XML from xml.dom import minidom # GET DATE #from cElementTree.SimpleXMLWriter import XMLWriter import string xml = minidom.Document() system_info = os.uname() siteElement = xml.createElement( 'Site' ) systeminfo = os.uname() siteElement.setAttribute( 'BuildName', system_info[0] + '-' + system_info[2] ) hostname = getfqdn() buildtype = 'Experimental' now = datetime.now() buildtime = str( now.year ) + str( now.month ) + str( now.day ) + "-" + str( now.minute ) + str( now.second ) #buildstamp = '20120603-0100-Nightly'# + '-' + buildtype buildstamp = buildtime + '-' + buildtype siteElement.setAttribute( 'BuildStamp', buildstamp ) siteElement.setAttribute( 'Name', hostname ) siteElement.setAttribute( 'Hostname', hostname ) xml.appendChild( siteElement ) buildElement = xml.createElement( 'Coverage' ) siteElement.appendChild( buildElement ) fillxml( xml, buildElement, 'StartDateTime', time.strftime( "%b %d %H:%M %Z", time.gmtime() ) ) fillxml( xml, buildElement, 'EndDateTime', time.strftime( "%b %d %H:%M %Z", time.gmtime() ) ) for f in covFiles: fileName = f[0] lines = f[1] testedLines = f[2] untestedLines = f[3] coveragePercent = f[4] fileElement = xml.createElement( 'File' ) fileElement.setAttribute( 'Name', os.path.split( fileName )[1] ) fileElement.setAttribute( 'FullPath', fileName ) fileElement.setAttribute( 'Covered', 'true' ) buildElement.appendChild( fileElement ) fillxml( xml, fileElement, 'LOCTested', str( testedLines ) ) fillxml( xml, fileElement, 'LOCUntested', str( untestedLines ) ) fillxml( xml, fileElement, 'PercentCoverage', str( coveragePercent ) ) fillxml( xml, buildElement, 'LOCTested', str( totalTestedLines ) ) fillxml( xml, buildElement, 'LOCUntested', str( int( totalLines ) - int( totalTestedLines ) ) ) fillxml( xml, buildElement, 'LOC', str( int( totalLines ) ) ) fillxml( xml, buildElement, 'PercentCoverage', str( totalCoverage ) ) f2 = open( 'XTKCoverage.xml', 'w' ) f2.write( xml.toxml() ) f2.close() browser.quit() return [result_unit, result]
def scrapeSOS(): filerId = sheet.getFilerId() filerId = filerId.replace(" ", "") if 'Nothing' in filerId: sys.exit("Nothing to tweet") print(filerId) display = Display(visible=0, size=(1341,810)) display.start() opts = Options() opts.add_argument("user-agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36") driver = webdriver.Chrome('/root/darkmoney/chromedriver', chrome_options=opts) driver.get("http://apps.azsos.gov/apps/election/cfs/search/AdvancedSearch.aspx") time.sleep(6) #This needs to take the filerID from the spreadsheet filerIdField = driver.find_element_by_id("ctl00_ctl00_PageContent_Sear"+ "chControlsContent_AdvancedSearchUserControl_FilerIdTextBox") actions = ActionChains(driver) actions.move_to_element(filerIdField) actions.click(filerIdField) filerIdField.clear() actions.send_keys(filerId + Keys.RETURN) actions.perform() time.sleep(6) address = driver.find_element_by_xpath('//*[@id="ctl00_ctl00_PageConte'+ 'nt_SearchControlsContent_AdvancedSearchDataUserControl_FilerD'+ 'ataRadGrid_ctl00__0"]/td[1]') filing_committee = address.text address.click() time.sleep(6) driver.find_element(By.LINK_TEXT, 'More >>').click() time.sleep(6) pdf_link = driver.find_element_by_xpath('//*[@id="ctl00_ctl00_PageCont'+ 'ent_SearchControlsContent_CommitteeDetailsPopupWindow_C_CommitteeDeta'+ 'ilsControl_CommitteeReportsWindow_C_CommitteeReportsControl_AllReport'+ 's_ReportsPreviousTable"]/tbody/tr[3]/td[4]/a') pdf_link.click() regex = re.compile('PublicReports.*pdf') pdf_link = pdf_link.get_attribute('href') pdf_link = regex.findall(pdf_link)[0] # Send the filing url to sheet.py pdf_url = 'http://apps.azsos.gov/apps/election/cfs/search/'+pdf_link #Switch to the new tab #readPDF(urlopen('http://apps.azsos.gov/apps/election/cfs/search/'+pdf_link)) req = Request(pdf_url, headers={'User-Agent': 'Mozilla/5.0'}) pdf = urlopen(req) with open("scrapedPDF.pdf", 'wb') as f: f.write(pdf.read()) f.close() darkmoney_rows = pdfScraper.scrape('scrapedPDF.pdf') sheet.fillSheet(darkmoney_rows, pdf_url, filing_committee, filerId) driver.quit()
from __future__ import print_function from selenium import webdriver from selenium.webdriver import ActionChains import time driver = webdriver.Remote( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={'browserName':'AutoIt'}) print("Desired Capabilities returned by server:\n") print(driver.desired_capabilities) print("") # demo adapted from AutoItX VBScript example that comes with AutoIt installation driver.get("notepad.exe") driver.switch_to_window("Untitled - Notepad") time.sleep(1) action1 = ActionChains(driver) action2 = ActionChains(driver) action3 = ActionChains(driver) action4 = ActionChains(driver) action1.send_keys("Hello, this is line 1{ENTER}").perform() time.sleep(1) action2.send_keys("This is line 2{ENTER}This is line 3").perform() time.sleep(1) action3.send_keys("!{F4}").perform() time.sleep(1) action4.send_keys("!n").perform() driver.quit()
elements = driver.find_elements_by_class_name("db10ub") html_source = driver.page_source soup = BeautifulSoup(html_source) table = soup.find('table', cellpadding='3') while y < len(elements): if soup.findAll('a',href=True): for item in table: y = str(y) element = driver.find_element_by_xpath('//table[2]/tbody/tr[4]/td/div/table/tbody/tr['+y+']/td[2]/font/a') y = int(y) element.click() y+=1 print y html_source = driver.page_source soup = BeautifulSoup(html_source) if soup.find('table', id='tabTwo'): element = driver.find_element_by_xpath("//tr[2]/td[6]/font/a") element.click() sleep(5) win = driver.window_handles driver.switch_to_window(win[1]) AC.key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform() sleep(1) AC.send_keys(Keys.ENTER) print "Saved" driver.switch_to_window(win[0]) driver.back() z+=1 driver.back()
action1 = ActionChains(ad) ### HTTP authentication dialog popup demo ### wd.get("http://www.httpwatch.com/httpgallery/authentication/") time.sleep(1) # check state that img is "unauthenticated" at start img_src = wd.find_element_by_id("downloadImg").get_attribute("src") if not img_src.endswith("/images/spacer.gif"): print("HTTP demo test fail because test site not started with correct default unauthenticated state.") # now test authentication wd.find_element_by_id("displayImage").click() # trigger the popup time.sleep(5) # wait for popup to appear ad.switch_to_window("Authentication Required") action1.send_keys("httpwatch{TAB}AutoItDriverServerAndSeleniumIntegrationDemo{TAB}{ENTER}").perform() time.sleep(5) # now check img is authenticated or changed img_src = wd.find_element_by_id("downloadImg").get_attribute("src") if img_src.endswith("/images/spacer.gif"): print("HTTP demo failed, image didn't authenticate/change after logging in.") ### file upload demo, also adapted from sample code of the test/target site ### wd.get("http://www.toolsqa.com/automation-practice-form") # wd.find_element_by_id("photo").click() # this doesn't seem to trigger file upload to popup elem = wd.find_element_by_id("photo") wd.execute_script("arguments[0].click();",elem) time.sleep(10) # wait for file upload dialog to appear ad.switch_to_window("File Upload")
def interact_keyboard( self ): ''' Perform some keyboard interaction in the current active browser window. ''' canvas = self.__browser.find_element_by_tag_name( 'canvas' ) actions = ActionChains( self.__browser ) actions.click( canvas ) # # keyboard events # # rotate for i in range( 30 ): actions.send_keys( Keys.ARROW_RIGHT ) for i in range( 30 ): actions.send_keys( Keys.ARROW_UP ) for i in range( 30 ): actions.send_keys( Keys.ARROW_LEFT ) for i in range( 30 ): actions.send_keys( Keys.ARROW_DOWN ) # zoom for i in range( 50 ): actions.key_down( Keys.LEFT_ALT ) actions.send_keys( Keys.ARROW_LEFT ) for i in range( 25 ): actions.key_down( Keys.LEFT_ALT ) actions.send_keys( Keys.ARROW_RIGHT ) # pan actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT ) actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_LEFT, Keys.ARROW_LEFT, Keys.ARROW_LEFT ) actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_UP, Keys.ARROW_UP, Keys.ARROW_UP ) actions.key_down( Keys.LEFT_SHIFT ) actions.send_keys( Keys.ARROW_DOWN, Keys.ARROW_DOWN ) actions.perform()
def _add_dataset(self, browser, organization): """ Add a simple dataset. Return dataset address. """ browser.get("https://localhost/en/dataset/new") browser.implicitly_wait(8) # Wait for javascript magic to alter fields try: field = browser.find_element_by_xpath("//input[@id='langtitle__0__value_id']") field.send_keys('Selenium Dataset') field = browser.find_element_by_xpath("//input[@name='agent__0__name']") field.send_keys('Selenium') field = browser.find_element_by_xpath("//input[@name='agent__0__organisation']") field.send_keys('CSC Oy') # Keywords -- the actual autocomplete field lacks the id attribute, so find it through an ancestor's sibling field = browser.find_element_by_xpath( "//input[@id='field-tags']/../div[@class='select2-container select2-container-multi']//input") field.send_keys('Selenium') field.send_keys(Keys.RETURN) field = browser.find_element_by_xpath("//input[@name='langdis']") field.click() field = browser.find_element_by_xpath("//input[@id='contact__0__name']") field.send_keys('Selenium contact') field = browser.find_element_by_xpath("//input[@id='contact__0__email']") field.send_keys('*****@*****.**') field = browser.find_element_by_xpath("//input[@id='contact__0__URL']") field.send_keys('https://localhost/') field = browser.find_element_by_xpath("//input[@id='contact__0__phone']") field.send_keys('+35891234567') field = browser.find_element_by_xpath("//input[@id='contact_owner']") field.click() field = browser.find_element_by_xpath("//input[@name='agent__3__name']") field.send_keys('Selenium') # field = browser.find_element_by_xpath("//select[@id='field-kata-pr']/option[@value='False']") # field.click() # field.send_keys('Published') field = browser.find_element_by_xpath( "//section/div/div/div/div[label[text()='Organisation']]/div/div/a") # CKAN Generated field ac = ActionChains(browser) ac.move_to_element_with_offset(field, 0.1, 0.1).click().perform() browser.implicitly_wait(2) for o in list(organization) + [Keys.RETURN]: ac.send_keys(o).perform() browser.implicitly_wait(2) browser.find_element_by_name("kata-accept-terms").click() browser.find_element_by_xpath("//*[contains(text(), 'Save and publish')]").click() except NoSuchElementException: browser.get_screenshot_as_file('_add_dataset.png') assert 0, "Error processing the create dataset page" try: WebDriverWait(browser, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//article/div/a[.='Hide/show']"))) except TimeoutException: browser.get_screenshot_as_file('_add_dataset.png') browser.quit() assert 0, "Dataset creation didn't finish" if not "Selenium Dataset" in browser.title: browser.get_screenshot_as_file('_add_dataset.png') browser.quit() assert 0, "Dataset creation failed somehow" return ''.join(browser.current_url)
driver = webdriver.Chrome('/home/qstin/chromedriver') driver.set_window_size(1440, 900) driver.get("http://apps.azsos.gov/apps/election/cfs/search/AdvancedSearch.aspx") time.sleep(5) #This needs to take the filerID from the spreadsheet filerId = str(filerID) filerIdField = driver.find_element_by_id("ctl00_ctl00_PageContent_Sear"+ "chControlsContent_AdvancedSearchUserControl_FilerIdTextBox") actions = ActionChains(driver) actions.move_to_element(filerIdField) actions.click(filerIdField) filerIdField.clear() actions.send_keys(filerId + Keys.RETURN) actions.perform() #waitForLoad(driver) time.sleep(3) address = driver.find_element_by_xpath('//*[@id="ctl00_ctl00_PageConte'+ 'nt_SearchControlsContent_AdvancedSearchDataUserControl_FilerD'+ 'ataRadGrid_ctl00__0"]/td[1]') print(address.text) address.click() time.sleep(3)
def test_storymap(self): factories.UserFactory.create( email="*****@*****.**", password="******", is_staff=True, ) self._login("*****@*****.**", "123") time.sleep(0.2) storymap = factories.StoryMapFactory.create() self.browser.get(self.live_reverse("storymap_detail", args=(storymap.pk,))) time.sleep(0.2) # Create 2 themes for seq in range(2): self.sel_query("a.create_theme").click() time.sleep(0.2) theme_input = self.sel_query("#theme-create-panel textarea") theme_input.send_keys("Theme {0}".format(seq)) self.sel_query("#create-theme-btn").click() time.sleep(0.5) # Create 2 phase for seq in range(2): self.sel_query("a.create_phase").click() time.sleep(0.2) theme_input = self.sel_query("#phase-create-panel textarea") theme_input.send_keys("Phase {0}".format(seq)) self.sel_query("#create-phase-btn").click() time.sleep(0.5) # let's move to the theme and phase to display the "new story" button actionChains = ActionChains(self.browser) actionChains.move_to_element(self.sel_query(".stories-zone")) actionChains.perform() time.sleep(0.2) self.sel_query(".create_story").click() time.sleep(0.2) actionChains = ActionChains(self.browser) actionChains.send_keys("My first story\n") actionChains.perform() time.sleep(0.2) actionChains = ActionChains(self.browser) actionChains.move_to_element(self.sel_query(".stories-zone")) actionChains.perform() time.sleep(0.2) self.sel_query(".create_story").click() actionChains = ActionChains(self.browser) actionChains.send_keys("My second story\n") actionChains.perform() time.sleep(0.2) story = Story.objects.get(title="My first story") phase_1 = Phase.objects.get(name="Phase 1") theme_0 = Theme.objects.get(name="Theme 0") # move story to another phase actionChains = ActionChains(self.browser) actionChains.drag_and_drop( self.sel_query('.story-cell[story-id="{0}"]'.format(story.pk)), self.sel_query('.stories-zone[phase-id="{0}"]'.format(phase_1.pk)), ) actionChains.perform() time.sleep(0.2) storymap = StoryMap.objects.get(pk=storymap.pk) self.assertEqual(storymap.themes.all()[0].name, "Theme 0") self.assertEqual(storymap.themes.all()[1].name, "Theme 1") self.assertEqual(storymap.phases.all()[0].name, "Phase 0") self.assertEqual(storymap.phases.all()[1].name, "Phase 1") story = Story.objects.get(title="My first story") self.assertEqual(story.phase_id, phase_1.pk) self.assertEqual(story.theme_id, theme_0.pk) # Edit story actionChains = ActionChains(self.browser) actionChains.click(self.sel_query( '.story-cell[story-id="{0}"] .story'.format( story.pk ) )) actionChains.perform() actionChains = ActionChains(self.browser) actionChains.send_keys(" Edited\n") actionChains.perform() time.sleep(1) self.assertTrue(Story.objects.get(title="My first story Edited")) # delete theme 1 theme = Theme.objects.get(name="Theme 1") actionChains = ActionChains(self.browser) actionChains.move_to_element(self.sel_query( '.theme-cell[theme-id="{0}"]'.format(theme.pk))) actionChains.click(self.sel_query( '.theme-cell[theme-id="{0}"] .delete_theme'.format(theme.pk))) actionChains.perform() time.sleep(0.2) self.sel_query("#confirm-delete-btn").click() time.sleep(0.5) # delete phase 0 phase = Phase.objects.get(name="Phase 0") actionChains = ActionChains(self.browser) actionChains.move_to_element(self.sel_query( '.phase-cell[phase-id="{0}"]'.format(phase.pk))) actionChains.click(self.sel_query( '.phase-cell[phase-id="{0}"] .delete_phase'.format(phase.pk))) actionChains.perform() time.sleep(0.2) self.sel_query("#confirm-delete-btn").click() time.sleep(0.5) # delete last story actionChains = ActionChains(self.browser) actionChains.move_to_element(self.sel_query( '.story-cell[story-id="{0}"]'.format(story.pk))) actionChains.click(self.sel_query( '.story-cell[story-id="{0}"] .delete_story'.format(story.pk))) actionChains.perform() time.sleep(0.2) self.sel_query("#confirm-delete-btn").click() time.sleep(0.5) # Only one story theme and phase should exists self.assertFalse(Story.objects.exists()) self.assertTrue(Theme.objects.get()) self.assertTrue(Theme.objects.get())
driver.find_element_by_id("93").click() # + time.sleep(1) driver.find_element_by_id("133").click() # 3 time.sleep(1) driver.find_element_by_id("121").click() # = time.sleep(1) if driver.find_element_by_id("150").text != "6": print("3 + 3 did not produce 6 as expected.") driver.find_element_by_id("81").click() # Clear "C" button time.sleep(1) # demo adapted from AutoItX VBScript example that comes with AutoIt installation action1 = ActionChains(driver) action2 = ActionChains(driver) action3 = ActionChains(driver) action1.send_keys("2*2=").perform() time.sleep(1) if driver.find_element_by_id("150").text != "4": print("2 x 2 did not produce 4 as expected.") driver.find_element_by_id("81").click() # Clear "C" button time.sleep(1) action2.send_keys("4*4=").perform() time.sleep(1) if driver.find_element_by_id("150").text != "16": print("4 x 4 did not produce 16 as expected.") driver.find_element_by_id("81").click() # Clear "C" button time.sleep(1) action3.send_keys("8*8=").perform() time.sleep(1) if driver.find_element_by_id("150").text != "64": print("8 x 8 did not produce 64 as expected.")
u"Tweets by @ShmooCon", u"General Ticket Information", ] tab_opened = False while True: driver.refresh() try: tbody = driver.find_element_by_id("main-section") links = tbody.find_elements_by_tag_name("a") except: pass for link in links: if hasattr(link, "text"): if link.text not in known_links and link.is_displayed() == True: tab_opened = True actions = ActionChains(driver) actions.move_to_element(link) actions.send_keys(Keys.COMMAND) actions.click(link) actions.perform() if tab_opened: print "Opened tab. Sleeping 10 seconds" time.sleep(10) time.sleep(0.1)