def deletar_filtros(self): try: if self.elemento_visivel(self.SELECT_FILTROS_CRIADOS): select = Select(self.get_elemento(self.SELECT_FILTROS_CRIADOS)) options = select.options del options[0] for opt in options: if self.elemento_visivel(self.SELECT_FILTROS_CRIADOS): self.clicar(self.DROPDOWN_FILTROS) self.clicar(self.BTN_EDITAR_FILTROS) WebDriverWait(self.driver, 10).until( EC.url_matches( 'https://mantis.saojudas.base2.com.br/manage_filter_page.php' )) self.clicar(self.BTN_DELETAR_FILTRO) self.clicar(self.BTN_CONFIRM_DELETE) WebDriverWait(self.driver, 10).until( EC.url_matches( 'https://mantis.saojudas.base2.com.br/manage_filter_page.php' )) self.clicar(self.ANCORA_VER_TAREFAS) WebDriverWait(self.driver, 10).until( EC.url_matches( 'https://mantis.saojudas.base2.com.br/view_all_bug_page.php' )) finally: return False
def login(self): self.driver.get('https://pc.xuexi.cn/points/login.html?ref=https://pc.xuexi.cn/points/my-points.html') if re.match(r'^https://pc.xuexi.cn/points/login.html.*', self.driver.current_url) and (login_method.get() == 'Dingtalk' or self.use_Dingtalk): self.driver.get('https://login.dingtalk.com/login/index.htm?goto=https%3A%2F%2Foapi.dingtalk.com%2Fconnect%2Foauth2%2Fsns_authorize%3F' 'appid%3Ddingoankubyrfkttorhpou%26response_type%3Dcode%26scope%3Dsnsapi_login%26redirect_uri%3Dhttps%3A%2F%2Fpc-api.xuexi.cn' '%2Fopen%2Fapi%2Fsns%2Fcallback') if self.use_Dingtalk: # use profile to login try: WebDriverWait(self.driver, 60).until(expected_conditions.presence_of_element_located( (By.ID, 'mobile'))) for div in self.driver.find_elements_by_id('mobilePlaceholder'): if div.text == u'请输入手机号码': div.click() self.driver.find_element_by_id('mobile').send_keys(config['dingtalk']['username']) if div.text == u'请输入密码': div.click() self.driver.find_element_by_id('pwd').send_keys(config['dingtalk']['password']) self.driver.find_element_by_id('loginBtn').click() except Exception: return False while (login_method.get() == 'Dingtalk' or self.use_Dingtalk)and not self.__exit_flag.isSet(): try: WebDriverWait(self.driver, 10).until(expected_conditions.url_matches(r'https://[a-z]*.xuexi.cn.*')) break except Exception: pass # self.driver.switch_to.frame('ddlogin-iframe') if re.match(r'^https://pc.xuexi.cn/points/login.html.*', self.driver.current_url) and login_method.get() == 'QR': # login_QR = WebDriverWait(self.driver, 10).until( # expected_conditions.presence_of_element_located((By.XPATH, '//div[@id="qrcode"]//img'))) # base64QR = login_QR.get_attribute('src') # imgData = base64.b64decode(base64QR[22:]) # nparr = np.fromstring(imgData, np.uint8) # img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR) # cv2.imshow("test",img_np) # cv2.waitKey(0) # current_image = Image.fromarray(img_np) # global app # app.show_img(current_image) # wait for login app.log(u'请扫码登陆') while not self.__exit_flag.isSet(): try: WebDriverWait(self.driver, 3).until( expected_conditions.presence_of_element_located((By.XPATH, '//div[@class="my-points-card-text"]'))) break except Exception: pass return True
def wait(self, timeout: int = 10): """Wait for the page to open.""" WebDriverWait(self.driver, timeout).until(url_matches(self.url)) WebDriverWait(self.driver, timeout).until(self.page_state_is("complete")) return self
def view_factor_detail(self, factor_row): code = self.get_factor_attribute(factor_row, 'code') logger.info("查看因子%s详情...", code) re_m = re.match(consts.FACTOR_CODE_PATTERN, code) if self.assertIsNotNone(re_m, f'无法打开详情页,因子编号{code}无效!'): try: self.driver.find_elements_by_xpath( f'//a[@href="#/factor/{re_m.group(1)}"]/button')[-1].click( ) try: WebDriverWait(self.driver, config.IMPLICIT_WAIT).until( EC.url_matches(DETAIL_URL_PATTERN)) if self.assertIn( re.match(DETAIL_URL_PATTERN, self.driver.current_url).group(1), code): logger.info("查看因子%s详情页成功!", code) else: logger.error("查看因子%s详情页失败!", code) except TimeoutException: logger.error("查看因子%s详情页失败!", code) finally: self.driver.find_element_by_xpath( r'//span[contains(text(), "返回")]/..').click() except NoSuchElementException as ex: self.assertIsNone(ex, f'无法找到因子{code}的查看button!')
def test_not_empty_field(self): driver = self.driver driver.get("http://127.0.0.1:8085/signup") first_name = driver.find_element_by_name("first_name") last_name = driver.find_element_by_name("last_name") username = driver.find_element_by_name("username") password = driver.find_element_by_name("password1") repassword = driver.find_element_by_name("password2") email = driver.find_element_by_name("email") phone_number = driver.find_element_by_name("phone_number") account_number = driver.find_element_by_name("account_number") register_button = driver.find_element_by_name("account_number") first_name.send_keys("ali") last_name.send_keys("alavi") username.send_keys("") password.send_keys("1q1q1q1q") repassword.send_keys("sadf;lksf") email.send_keys("*****@*****.**") phone_number.send_keys("09121234567") account_number.send_keys("123456") register_button.click() time.sleep(3) try: WebDriverWait(driver, 2) \ .until(expected_conditions.url_matches("http://127.0.0.1:8085/signup")) flag = True except TimeoutException: flag = False assert flag
def validate_redirect(page: HomePage): try: redirect = WebDriverWait(page.browser, 4).until(expected_conditions.url_matches(url)) assert redirect except TimeoutException: raise AssertionError("no redirect")
def toCart(): driver.get("https://cart.taobao.com/") WebDriverWait(driver, 10, 0.0001).until(EC.url_matches("https://cart.taobao.com/")) WebDriverWait(driver, 10, 0.0001).until( EC.presence_of_element_located((By.ID, "J_SelectAll1"))) driver.find_element_by_id("J_SelectAll1").click()
def login(self): print("Loading webdriver") self.driver = driver = webdriver.Firefox() print("Webdriver loaded") driver.get(self.endpoints['login']) try: loginfound = EC.visibility_of_element_located((By.CSS_SELECTOR, "form#j_idt13")) WebDriverWait(driver, 10).until(loginfound) except TimeoutException as e: print("Timout on login form") raise e else: print("Loaded login page") login_form = driver.find_element_by_css_selector("form#j_idt13") user_input = login_form.find_element_by_css_selector("input#j_idt13\:username") user_input.clear() user_input.send_keys(self.username) pass_input = login_form.find_element_by_css_selector("input#j_idt13\:password") pass_input.clear() pass_input.send_keys(self.password) login_form.find_element_by_css_selector("input#j_idt13\:submitLogin").click() # driver.implicitly_wait(10) # Ensure page loaded before proceding try: WebDriverWait(driver, 10).until(EC.url_matches(self.endpoints['dashboard'])) except TimeoutException as e: print("Timout on loading dashboard") raise e else: print("Logged in, dashboard loaded")
def test_register_login(self): print("Testing register login") self.assertFalse( self.driver.find_element_by_id('id_invalid_user').is_displayed()) self.assertFalse( self.driver.find_element_by_id('id_existing_user').is_displayed()) self.register_user('username', 'password') self.wait.until(EC.url_changes(self.deployment_url)) self.assertEqual(self.driver.current_url, self.deployment_url + "homepage") self.driver.get(self.deployment_url) self.register_user('username', 'password') self.wait.until( EC.visibility_of( self.driver.find_element_by_id('id_existing_user'))) self.assertTrue( self.driver.find_element_by_id('id_existing_user').is_displayed()) self.driver.find_element_by_id('id_sign_in').click() self.login_user('username', 'password') self.wait.until(EC.url_changes(self.deployment_url)) self.assertEqual(self.driver.current_url, self.deployment_url + 'homepage') self.driver.get(self.deployment_url) self.wait.until(EC.url_matches(self.deployment_url)) self.login_user('username', 'pass') self.wait.until( EC.visibility_of( self.driver.find_element_by_id('id_invalid_user'))) self.assertTrue( self.driver.find_element_by_id('id_invalid_user').is_displayed())
def test_register_login(self): self.assertFalse( self.driver.find_element_by_id('id_invalid_user').is_displayed()) self.assertFalse( self.driver.find_element_by_id('id_existing_user').is_displayed()) self.register_user('username', 'password') self.wait.until(EC.url_changes('http://whiskeding.herokuapp.com/')) self.assertEqual(self.driver.current_url, 'http://whiskeding.herokuapp.com/homepage') self.driver.get('http://whiskeding.herokuapp.com') self.register_user('username', 'password') self.wait.until( EC.visibility_of( self.driver.find_element_by_id('id_existing_user'))) self.assertTrue( self.driver.find_element_by_id('id_existing_user').is_displayed()) self.driver.find_element_by_id('id_sign_in').click() self.login_user('username', 'password') self.wait.until(EC.url_changes('http://whiskeding.herokuapp.com/')) self.assertEqual(self.driver.current_url, 'http://whiskeding.herokuapp.com/homepage') self.driver.get('http://whiskeding.herokuapp.com/') self.wait.until(EC.url_matches('http://whiskeding.herokuapp.com/')) self.login_user('username', 'pass') self.wait.until( EC.visibility_of( self.driver.find_element_by_id('id_invalid_user'))) self.assertTrue( self.driver.find_element_by_id('id_invalid_user').is_displayed())
def __get__( self, page_object: PageObject, page_object_cls: type ) -> Union["PageResource", str]: if not page_object: return self browser = page_object.browser current_url = browser.current_url if current_url[-1] == "/": current_url = current_url[:-1] assert ( self._ref in browser.page_source ), f"no '{self._ref}' found on page at {current_url}" resource_url = f"{current_url}{self._ref}" try: browser.get(resource_url) found = WebDriverWait(browser, 4).until( expected_conditions.url_matches(resource_url) ) assert found, f"browser does not open url {resource_url}" content = browser.page_source return content finally: browser.get(current_url)
def test_transfert_is_ok(self): self.open_live_url(reverse("otpadmin:aidants_connect_web_mandat_transfer")) self.__login() self.__transfer_mandate( [self.mandate_1, self.mandate_2], self.aidante_fatimah.organisation.pk ) wait = WebDriverWait(self.selenium, 10) wait.until( url_matches( f"^.+{reverse('otpadmin:aidants_connect_web_mandat_changelist')}$" ) ) self.assertEqual( Mandat.objects.get(pk=self.mandate_1.pk).organisation, self.aidante_fatimah.organisation, ) self.assertEqual( Mandat.objects.get(pk=self.mandate_2.pk).organisation, self.aidante_fatimah.organisation, ) self.assertEqual( Mandat.objects.get(pk=self.mandate_3.pk).organisation, self.aidant_thierry.organisation, ) self.assertEqual( Mandat.objects.get(pk=self.mandate_4.pk).organisation, self.aidant_thierry.organisation, )
def test_valid(self): edid_binary = b'\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x52\x62\x06\x02\x01' \ b'\x01\x01\x01\xFF\x13\x01\x03\x80\x59\x32\x78\x0A\xF0' \ b'\x9D\xA3\x55\x49\x9B\x26\x0F\x47\x4A\x21\x08\x00\x81' \ b'\x80\x8B\xC0\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01' \ b'\x01\x01\x02\x3A\x80\x18\x71\x38\x2D\x40\x58\x2C\x45' \ b'\x00\x76\xF2\x31\x00\x00\x1E\x66\x21\x50\xB0\x51\x00' \ b'\x1B\x30\x40\x70\x36\x00\x76\xF2\x31\x00\x00\x1E\x00' \ b'\x00\x00\xFC\x00\x54\x4F\x53\x48\x49\x42\x41\x2D\x54' \ b'\x56\x0A\x20\x20\x00\x00\x00\xFD\x00\x17\x3D\x0F\x44' \ b'\x0F\x00\x0A\x20\x20\x20\x20\x20\x20\x01\x24' edid_file = self._create_temp_file(edid_binary) edid_file.close() self.browser.get("%s/edid/upload/binary" % self.live_server_url) self.browser.find_element_by_id('id_edid_file')\ .send_keys(edid_file.name) # Submit upload form self.browser.find_element_by_id('upload-id-upload').click() WebDriverWait(self.browser, 30).until( url_matches("%s/edid/[0-9]+/" % self.live_server_url), 'Should redirect to EDID detail page')
def validate_redirect(page: HelloPage, url: str): try: redirected = WebDriverWait(page.browser, 4).until( expected_conditions.url_matches(url)) assert redirected except TimeoutException as err: raise AssertionError("no redirect") from err
def get_authorization(): """ 登录并获取授权相关信息 :return: access_token, user-agent """ with AutoClosableChrome(CHROME_DRIVER_PATH) as driver: driver.get(ZsxqApi.URL_LOGIN) # 获取User-Agent user_agent = driver.execute_script("return navigator.userAgent") # 等待跳转至主页 WebDriverWait(driver, 60).until(url_matches(r'index/group/init')) logger.info('登录成功') # 等待access_token加载完毕 access_token = WebDriverWait(driver, 30).until(cookie_is_set('zsxq_access_token')) access_token = access_token['value'] # 等待头像加载完毕 # 直接返回的token是不合法的,需要等待浏览器提交某请求使其合法,而该提交先于头像的加载 # TODO: 似乎是加密了,有空再分析该请求 # avatar_complete = element_is_complete((By.CSS_SELECTOR, 'p.avastar-p img')) # WebDriverWait(driver, 30).until(avatar_complete) logger.info('access_token加载成功: %s' % access_token) logger.info('user-agent加载成功: %s' % user_agent) # exit() return access_token, user_agent
def handle_redirect(browser, valid_dest=None, timeout=None, route=None): current = browser.current_url log.warning("Redirected to: '{}'".format(current)) if browser.Patterns.AUTH_URL in current: wait_for_auth(browser) elif browser.Patterns.OOS_URL in current: handle_oos(browser) elif browser.Patterns.THROTTLE_URL in current: handle_throttle(browser) raise RouteRedirect('Redirected after throttle') elif route and current == route.route_start: if not route.waypoints_reached: browser.driver.refresh() raise RouteRedirect() elif valid_dest and timeout: log.warning( 'Handling unknown redirect (timeout in {}s)'.format(timeout) ) try: WebDriverWait(browser.driver, timeout).until( EC.url_matches('|'.join(valid_dest)) ) except TimeoutException: raise UnhandledRedirect( "Timed out waiting for redirect to a valid dest\n" "Current URL: '{}'".format(browser.current_url) ) else: raise UnhandledRedirect()
def get_code(email, password): driver = webdriver.Firefox() driver.set_window_size(600, 800) driver.get('https://www.epicgames.com/id/login/epic') WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, 'email'))) email_input = driver.find_element_by_id('email') email_input.send_keys(email) password_input = driver.find_element_by_id('password') password_input.send_keys(password) WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, 'sign-in'))) signin_button = driver.find_element_by_id('sign-in') signin_button.click() print('Wait for entering 2-FA code and/or solving captcha...') WebDriverWait(driver, 60 * 60).until( EC.url_matches('https://www.epicgames.com/account/personal')) driver.get( 'view-source:https://www.epicgames.com/id/api/redirect?clientId=3446cd72694c4a4485d81b77adbb2141&responseType=code' ) WebDriverWait(driver, 30).until( EC.presence_of_element_located((By.TAG_NAME, 'pre'))) pre = driver.find_element_by_tag_name("pre").text driver.close() url = json.loads(pre)['redirectUrl'] code = url.split('?code=')[1] return code
def test_delete_some_contact_via_main_view(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.add( Contact(firstname="faname", lastname="lname", address="address", homephone="1", mobilephone="2", workphone="3", fax="3", email="e1", email2="e2", email3="e3")) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) app.contact.delete_contact_by_id_via_main_view(contact.id) WebDriverWait(app.wd, 5).until(EC.url_matches(app.base_url), 'Delete failed, not redirected to main page?') new_contacts = db.get_contact_list() assert len(old_contacts) - 1 == len(new_contacts) old_contacts.remove(contact) assert old_contacts == new_contacts if check_ui: for index, contact_item in enumerate(old_contacts): formatted_contact = app.contact.contact_like_on_webpage( contact_item) old_contacts[index] = formatted_contact assert sorted(old_contacts, key=Contact.id_or_max) == sorted( app.contact.get_contact_list(), key=Contact.id_or_max)
def upload(fit_file): chrome_driver.get("https://www.endomondo.com/workouts/create") try: # Handle import type selection. wait = WebDriverWait(chrome_driver, 10) # wait.until(EC.element_to_be_clickable((By.XPATH, '//a[@id="ida"]'))).click() fileimport_div = wait.until( EC.element_to_be_clickable( (By.XPATH, '//div[@class="fileImport"]'))) step_up = fileimport_div.find_element_by_xpath("..") fileimport_btn = step_up.find_element_by_xpath("..") fileimport_btn.click() # Handle the file selection iframe. WebDriverWait(chrome_driver, 10).until( EC.frame_to_be_available_and_switch_to_it( (By.CLASS_NAME, "iframed"))) upload_file = wait.until( EC.element_to_be_clickable( (By.XPATH, '//input[@name="uploadFile"]'))) full_path = os.path.abspath(fit_file) upload_file.send_keys(full_path) chrome_driver.find_element_by_xpath( '//a[@name="uploadSumbit"]').click() wait.until( EC.element_to_be_clickable( (By.XPATH, '//a[@name="reviewSumbit"]'))).click() wait.until(EC.url_matches("/workouts/latest$")) # Transfer done, rename file. shutil.move(full_path, "{}.done".format(full_path)) except TimeoutException: print("Timed out while waiting to click file import buttons.") exit()
def __transfer_mandate(self, mandates: Sequence[Mandat], organisation: int): wait = WebDriverWait(self.selenium, 10) # Select mandates 1 & 2 for mandate in mandates: self.selenium.find_element( By.XPATH, f"//table//input[@value='{mandate.pk}']" ).click() # Select action Select( self.selenium.find_element( By.XPATH, "//form[@id='changelist-form']//select[@name='action']" ) ).select_by_visible_text( MandatAdmin.move_to_another_organisation.short_description ) # Submit form ids = sorted([str(mandate.pk) for mandate in mandates], key=int) path = reverse("otpadmin:aidants_connect_web_mandat_transfer") self.selenium.find_element( By.XPATH, "//form[@id='changelist-form']//button[@type='submit']" ).click() wait.until(url_matches(f"^.+{path}\\?ids={','.join(ids)}$")) # Transfer to new organisation field = self.selenium.find_element(By.XPATH, "//input[@name='organisation']") field.clear() field.send_keys(organisation) self.selenium.find_element(By.XPATH, "//input[@type='submit']").click()
def test_valid(self): edid_binary = b'\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x52\x62\x06\x02\x01' \ b'\x01\x01\x01\xFF\x13\x01\x03\x80\x59\x32\x78\x0A\xF0' \ b'\x9D\xA3\x55\x49\x9B\x26\x0F\x47\x4A\x21\x08\x00\x81' \ b'\x80\x8B\xC0\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01' \ b'\x01\x01\x02\x3A\x80\x18\x71\x38\x2D\x40\x58\x2C\x45' \ b'\x00\x76\xF2\x31\x00\x00\x1E\x66\x21\x50\xB0\x51\x00' \ b'\x1B\x30\x40\x70\x36\x00\x76\xF2\x31\x00\x00\x1E\x00' \ b'\x00\x00\xFC\x00\x54\x4F\x53\x48\x49\x42\x41\x2D\x54' \ b'\x56\x0A\x20\x20\x00\x00\x00\xFD\x00\x17\x3D\x0F\x44' \ b'\x0F\x00\x0A\x20\x20\x20\x20\x20\x20\x01\x24' edid_file = self._create_temp_file(edid_binary) edid_file.close() self.browser.get("%s/edid/upload/binary" % self.live_server_url) self.browser.find_element_by_id('id_edid_file')\ .send_keys(edid_file.name) # Submit upload form self.browser.find_element_by_id('upload-id-upload').submit() WebDriverWait(self.browser, 30).until( url_matches("%s/edid/[0-9]+/" % self.live_server_url), 'Should redirect to EDID detail page' )
def buy(): # 打开购物车 # WebDriverWait(driver, 10, 0.1).until(EC.presence_of_element_located((By.ID, "J_SelectAll1"))) # driver.find_element_by_id("J_SelectAll1").click() WebDriverWait(driver, 10, 0.0001).until(EC.url_matches("https://cart.taobao.com/")) WebDriverWait(driver, 1000, 0.1).until( EC.presence_of_element_located((By.ID, "J_SelectAll1"))) driver.find_element_by_id("J_SelectAll1").click() submit_succ = False retry_submit_times = 0 while True: now = datetime.datetime.now() if now >= buy_time_object: retry_submit_times = retry_submit_times + 1 if submit_succ or (retry_submit_times > 6): print("订单已经提交成功,无需继续抢购...") return try: # 点击结算按钮 WebDriverWait(driver, 100, 0.00001).until( EC.presence_of_element_located((By.ID, "J_Go"))) driver.find_element_by_id("J_Go").click() print("已经点击结算按钮...") while True: WebDriverWait(driver, 10, 0.00001).until(EC.url_matches("https://buy")) WebDriverWait(driver, 10, 0.00001).until( EC.presence_of_element_located( (By.PARTIAL_LINK_TEXT, "提交"))) driver.find_element_by_partial_link_text('提交').click() # __buy_error_code if 'https://cashierem14.alipay.com/' in driver.current_url: submit_succ = True pass else: WebDriverWait(driver, 10, 0.00001).until( EC.url_matches("__buy_error_code")) driver.back() except Exception as e: if 'https://cashierem14.alipay.com/' in driver.current_url: print("提交订单成功") return print("不好,挂了,提交订单失败了...") toCart() # time.sleep(5) time.sleep(0.000001)
def _perform_submit(webdriver=None): submit_btn = webdriver.find_element_by_css_selector( 'input[type="submit"][name="_save"]') webdriver.execute_script("arguments[0].click();", submit_btn) WebDriverWait(webdriver, 10).until(EC.url_matches(f'{ORIGIN_URL}/patients/(?!new)')) logger.info('Save patient successful')
def ir_para_pagina_conta(self): if self.elemento_visivel(self.DROPDOWN): self.clicar(self.DROPDOWN) self.clicar(self.CONTA_BTN) WebDriverWait(self.driver, 10).until( EC.url_matches( 'https://mantis.saojudas.base2.com.br/account_page.php')) return AccountPage(self.driver)
def login(browser, timeout): logger = logging.getLogger("LOGIN") browser.get(LOGIN_URL) WebDriverWait(browser, timeout).until( EC.url_matches(POST_LOGIN_URL_PATTERN) ) sleep(REFRESH_WAIT) logger.info('Successfully logged in!')
def test_sandbox(live_server, logged_in_browser): """ Test adding, modifying and deleting a sandbox record """ browser = logged_in_browser browser.file_detector = LocalFileDetector() # Go to sandbox sandbox_url = flask.url_for('hepdata_records.sandbox', _external=True) browser.get(sandbox_url) e2e_assert_url(browser, 'hepdata_records.sandbox') # Check there are no past sandbox submissions assert browser.find_element_by_id('past_submissions') \ .find_elements_by_xpath(".//*") == [] # Try uploading a file upload = browser.find_element_by_id('root_file_upload') ActionChains(browser).move_to_element(upload).perform() upload.send_keys(os.path.abspath("tests/test_data/TestHEPSubmission.zip")) browser.find_element_by_class_name('btn-primary').click() # Should redirect to record page with confirmation message WebDriverWait(browser, 15).until( EC.url_matches(f'{sandbox_url}/\\d+') ) alert = browser.find_element_by_class_name('alert-info') assert alert.text == "File saved. You will receive an email when the file has been processed." # Record should have been processed immediately by test celery runner # so we can check its contents _check_record_common(browser) # Go back to the sandbox browser.get(sandbox_url) # Check that past submissions column now has a child past_submissions_div = browser.find_element_by_id('past_submissions') assert len(past_submissions_div.find_elements_by_class_name('col-md-10')) == 1 # Delete the sandbox record past_submissions_div.find_element_by_class_name('delete_button').click() delete_modal = browser.find_element_by_id('deleteWidget') WebDriverWait(browser, 10).until( EC.visibility_of(delete_modal) ) delete_modal.find_element_by_class_name('confirm-delete').click() WebDriverWait(browser, 10).until( EC.text_to_be_present_in_element((By.ID, 'deleteDialogLabel'), 'Submission Deleted') ) # Refresh sandbox page (to avoid waiting) browser.get(sandbox_url) # Check there are no past sandbox submissions assert browser.find_element_by_id('past_submissions') \ .find_elements_by_xpath(".//*") == []
def editar_plataforma(self, novaPlataforma): input = self.get_elemento(self.PLATAFORMA) input.clear() self.enviar_teclas(self.PLATAFORMA, novaPlataforma) self.clicar(self.BTN_SALVAR) WebDriverWait(self.driver, 10).until( EC.url_matches( 'https://mantis.saojudas.base2.com.br/account_prof_menu_page.php' ))
def login(): options = webdriver.ChromeOptions() options.add_argument("user-data-dir=selenium/chrome_driver") driver = webdriver.Chrome(executable_path="selenium/chromedriver.exe", chrome_options=options) driver.get("https://keats.kcl.ac.uk/") WebDriverWait(driver, 9999).until(EC.url_matches("https://keats.kcl.ac.uk/")) driver.quit()
def login(): print("开始尝试登录...") __login_operates() WebDriverWait(driver, 100, 0.0001).until(EC.url_matches("https://www.taobao.com")) # time.sleep(3) now = datetime.datetime.now() print('login success:', now.strftime('%Y-%m-%d %H:%M:%S'))
def wait_for_pin_number_and_select_it( wait: WebDriverWait, driver: webdriver.remote.webdriver.WebDriver): wait.until( expected_conditions.url_matches('https://sws-gateway.schwab.com/.*')) driver.switch_to.window(driver.window_handles[0]) pin_element = driver.find_element(By.ID, "placeholderCode") # Initially the element is findable but not clickable. When that happens, # the click operation fails, so wait for the element to be visible. wait.until(expected_conditions.visibility_of(pin_element)) pin_element.click() return pin_element
def check_article(selenium, article_url): WebDriverWait(selenium, 10).until(EC.url_matches(f'{URL}articles')) assert selenium.find_element_by_class_name('badge-rdltr').text == 'default' assert selenium.find_element_by_tag_name('h1').text == 'this is a title' assert ( article_url in selenium.find_element_by_class_name('article-data').text ) assert ( selenium.find_element_by_id('article-content').text == 'this is a paragraph' )