def test_search_in_google(self): driver = self.driver driver.get("https://www.google.co.in/") self.assertIn("Google", driver.title) elem = driver.find_element_by_id("gb_70") elem.send_keys() elem.send_keys(Keys.RETURN) gmailUsername = "******" gmailPassword = "******" emailFieldID = "Email" passFieldID = "Passwd" signInFieldXpath = "//input[@id='signIn']" emailFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(passFieldID)) signInFieldElement = WebDriverWait(driver, 10).until( lambda driver: driver.find_element_by_xpath(signInFieldXpath) ) emailFieldElement.clear() emailFieldElement.send_keys(gmailUsername) passFieldElement.clear() passFieldElement.send_keys(gmailPassword) signInFieldElement.click()
def login_adriaticapress(self): '''Creazione webdriver e procedura di login in adriatipress ''' try: with open('secrets.txt') as credentials_file: credentials_file_list = list(credentials_file.readlines()) username = credentials_file_list[0].strip()[9:] password = credentials_file_list[1].strip()[9:] except FileNotFoundError: self.msg = QMessageBox() self.msg.setText('File credenziali non presente') self.msg.setWindowTitle('testtitolo') self.msg.setStandardButtons(QMessageBox.Ok) return self.msg.exec_() if os.name == 'nt': self.dr = webdriver.Chrome('chromedriver.exe') else: self.dr = webdriver.Chrome() self.dr.maximize_window() self.dr.get('{}Login.htm'.format(ip_ap)) time.sleep(5) username_field = WebDriverWait(self.dr, 15).until(EC.presence_of_element_located((By.ID, 'txtUsername'))) password_field = WebDriverWait(self.dr, 15).until(EC.presence_of_element_located((By.ID, 'txtPassword'))) username_field.clear() username_field.send_keys(username) password_field.clear() password_field.send_keys(password) password_field.send_keys(Keys.RETURN) time.sleep(5)
def login(self, browser): """ 利用配置文件和初始化信息进行模拟登陆 :param:浏览器对象,已打开原始的登录页面 :return:浏览器对象 """ browser.get( self.config['BussinessStaffURL'] ) browser.switch_to.frame( browser.find_element_by_tag_name("iframe") ) userNameInput = browser.find_element_by_name("TPL_username") userNameInput.clear() userNameInput.send_keys( self.username+Keys.TAB+self.password+Keys.RETURN ) browser.switch_to.default_content() loopKey = True while loopKey: try: WebDriverWait( browser, 4 ).until( EC.presence_of_element_located( ( By.CSS_SELECTOR, "ul>li>a>div>strong>span" ) ) ) loopKey = False except Exception: browser.switch_to.frame( browser.find_element_by_tag_name("iframe") ) passwordInput = WebDriverWait(browser,10).until( EC.presence_of_element_located( (By.ID, "TPL_password_1") ) ) passwordInput.clear() passwordInput.send_keys( self.password ) checkCodeInput = WebDriverWait(browser,10).until( EC.presence_of_element_located( (By.ID,"J_CodeInput_i") ) ) checkCode = enterbox("请输入验证码(不区分大小写)","验证码输入","", True) checkCodeInput.send_keys(checkCode+Keys.RETURN) browser.switch_to.default_content() loopKey = True return browser
def buyMW(self, company, amount): #go to trade website self.driver.get("http://www.marketwatch.com/game/alecfongtest2/trade") driver = self.driver #get Xpath companyFieldXpath = ".//*[@id='fakemaincontent']/section/div[1]/div/input" searchbuttonXpath = ".//*[@id='fakemaincontent']/section/div[1]/div/button" #initialize elements compFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(companyFieldXpath)) searchButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(searchbuttonXpath)) compFieldElement.clear() #enter company symbol compFieldElement.send_keys(company) #click to search searchButtonElement.click() tradeFieldXpath = ".//*[@id='fakemaincontent']/section/div[2]/div/div[3]/div/button[2]" tradeFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(tradeFieldXpath)) #click to trade tradeFieldElement.click() shareamountXpath = "//input[@value='0']" submittradeXpath = ".//*[@id='submitorder']/button" shareamountElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(shareamountXpath)) submittradeElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(submittradeXpath)) shareamountElement.clear() shareamountElement.send_keys(str(amount)) submittradeElement.click()
def when_i_configure_valo_url(step): valo_url = WebDriverWait(world.driver, 5).until( EC.presence_of_element_located((By.CSS_SELECTOR, '[data-type=valoLocation]') ) ) valo_url.clear() valo_url.send_keys(world.valo_url)
def test_Login(self): driver = self.driver driver.get("https://virgin-red-test.appspot.com/backoffice/#/") VirginUsername = "******" VirginPassword = "******" #threeLogoXpath = "//*[@id='ember360']/div[1]/div/div[1]/div/img" # FieldID's and Xpath for elements emailFieldXpath = "/html/body/div[1]/div/div[2]/div/form/div[1]/input" passFieldXpath = "/html/body/div[1]/div/div[2]/div/form/div[2]/input" #rememberXpath = "//*[@id='login_form']/div[4]/label" loginFieldXpath = "/html/body/div[1]/div/div[2]/div/form/button" #WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(threeLogoXpath)) emailFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_xpath(emailFieldXpath)) passFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_xpath(passFieldXpath)) #rememFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_xpath(rememberXpath)) loginFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_xpath(loginFieldXpath)) # Login into the application emailFieldElement.clear() emailFieldElement.send_keys(VirginUsername) passFieldElement.clear() passFieldElement.send_keys(VirginPassword) #rememFieldElement.click() loginFieldElement.click() print("Login Successfull")
def write_date_thesis(date_field, error_message_id, date): try: WebDriverWait(Arsenic(), 5).until( EC.visibility_of_element_located((By.ID, date_field)) ) except (ElementNotVisibleException, WebDriverException): _skip_import_data() _select_thesis() field = WebDriverWait(Arsenic(), 5).until( EC.visibility_of_element_located((By.ID, date_field)) ) field.send_keys(date) Arsenic().hide_title_bar() Arsenic().click_with_coordinates('state-group-supervisors', 5, 5) try: error_message = WebDriverWait(Arsenic(), 5).until( EC.visibility_of_element_located((By.ID, error_message_id)) ).text except (ElementNotVisibleException, WebDriverException): error_message = '' Arsenic().show_title_bar() field.clear() def _has_error(): return ( 'Please, provide a valid date in the format YYYY-MM-DD, YYYY-MM ' 'or YYYY.' ) in error_message return ArsenicResponse(_has_error)
def write_pdf_link(pdf_link): def _write_pdf_link(): return ( 'Please, provide an accessible direct link to a PDF document.' ) in message_err try: WebDriverWait(Arsenic(), 5).until( EC.visibility_of_element_located((By.ID, 'url')) ) except (ElementNotVisibleException, WebDriverException): _skip_import_data() field = WebDriverWait(Arsenic(), 5).until( EC.visibility_of_element_located((By.ID, 'url')) ) field.send_keys(pdf_link) Arsenic().hide_title_bar() Arsenic().click_with_coordinates('state-group-url', 5, 5) try: message_err = WebDriverWait(Arsenic(), 10).until( EC.visibility_of_element_located((By.ID, 'state-url')) ).text except (ElementNotVisibleException, WebDriverException): message_err = '' Arsenic().show_title_bar() field.clear() return ArsenicResponse(_write_pdf_link)
def sellMW(self, company, buylist, amount): self.driver.get("http://www.marketwatch.com/game/alecfongtest2/portfolio/Holdings") driver = self.driver companysellbutXpath = ".//*[@id='maincontent']/section[2]/div[1]/table/tbody/tr[1]/td[7]/button" submitsaleXpath = "//div[3]/button" sortbysymbolXpath = "//a[contains(text(),'Symbol')]" shareamountXpath = "//div[@id='order']/div/div/div[2]/div/div/a/input" companysellbutElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(companysellbutXpath)) submitsaleElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(submitsaleXpath)) sortbysymbolElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(sortbysymbolXpath)) shareamountElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(shareamountXpath)) if(company < buylist[0] or company < buylist[1]): companysellbutElement.click() time.sleep(2) shareamountElement.clear() shareamountElement.send_keys(amount) submitsaleElement.click() else: sortbysymbolElement.click() time.sleep(2) companysellbutElement.click() time.sleep(2) shareamountElement.clear() shareamountElement.send_keys(amount) submitsaleElement.click()
def getupc(data, sleeptime): display = Display(visible=0, size=(800, 600)) display.start() a = webdriver.Firefox() a.get('https://www.google.com/ncr') time.sleep(sleeptime) search = WebDriverWait(a, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='text']"))) for i in data: ActionChains(a).move_to_element(search).click(search).send_keys(i['name'] + ' upc', Keys.ENTER).perform() time.sleep(sleeptime) contents = WebDriverWait(a, 5).until(EC.presence_of_all_elements_located((By.XPATH, "//div[@class='g']"))) try: upc = next( (re.split(r'/', href.find_element_by_tag_name('a').get_attribute('href'))[-1] for href in contents if href.find_element_by_tag_name('a').get_attribute('href').startswith( 'http://www.upcitemdb.com/upc'))) i['upc'] = upc except StopIteration: pass search = WebDriverWait(a, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='text']"))) search.clear() a.close() display.stop() return data
def sendMessageToSelected(message): element = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.TAG_NAME,'swx-textarea'))) element = element.find_element_by_tag_name("textarea") element.click() element.clear() element.send_keys(message) element.send_keys(Keys.ENTER)
def test_Login(self): driver = self.driver driver.get("https://wqd-stage.3m.com/3madmin/#/") ThreeMUsername = "******" ThreeMPassword = "******" # FieldID's and Xpath for elements emailFieldID = "username" passFieldID = "password" rememberXpath = "//*[@id='login_form']/div[4]/label" loginFieldXpath = "//*[@id='loginFormSubmit']" WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(threeLogoXpath)) emailFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_id(passFieldID)) rememFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_xpath(rememberXpath)) loginFieldElement = WebDriverWait (driver, 10).until(lambda driver: driver.find_element_by_xpath(loginFieldXpath)) # Login into the application emailFieldElement.clear() emailFieldElement.send_keys(ThreeMUsername) passFieldElement.clear() passFieldElement.send_keys(ThreeMPassword) rememFieldElement.click() loginFieldElement.click() print("Login Successfull")
def find_series_fanserials(browser, data): name = data[0] + ' ' + data[1] + ' сезон ' + data[2] + ' серия' rv = '' elem = WebDriverWait(browser, 5).until( EC.element_to_be_clickable((By.NAME, 'story')) ) # elem.click() elem.clear() elem.send_keys(name) elem.send_keys(Keys.RETURN) try: articles = browser.find_elements_by_css_selector('article') for article in articles: h5 = article.find_element_by_tag_name('h5') if (name.lower() in h5.text.lower()): a = h5.find_element_by_partial_link_text(data[1] + ' сезон') rv = a.text + ' | ' + a.get_attribute('href') except NoSuchElementException: pass if rv: print('\n', rv) else: print('.', end='')
def _login(self, with_email=False): jack_user = create_user_jack(active=True) browser = self.browser browser.get(self.site_url + reverse('login')) input_login = WebDriverWait(browser, 10).until( lambda browser: browser.find_element_by_xpath("//input[@id='id_email_or_username']")) input_password = WebDriverWait(browser, 10).until( lambda browser: browser.find_element_by_xpath("//input[@id='id_password']")) input_login.clear() if with_email: input_login.send_keys(jack_user.email) else: input_login.send_keys(jack_user.username) input_password.clear() input_password.send_keys('pass') submit_button = WebDriverWait(browser, 10).until( lambda browser: browser.find_element_by_xpath("//input[@type='submit']")) submit_button.click() return jack_user
def test_challenge(self, user, passwd): mailstring = user + '@user.com' email = WebDriverWait(self, 10).until(lambda self: self.browser.find_element_by_name("email")) email.send_keys(mailstring) password = self.browser.find_element_by_name("password") password.send_keys(passwd) submit_button = self.browser.find_element_by_css_selector("#submit_record__row input") submit_button.click() time.sleep(1) #self.url = ROOT + "/viewquest/index/4" self.url = functional_tests.questref get_browser=self.browser.get(self.url) time.sleep(2) challreason = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_name("challreason")) #self.browser.find_element_by_name("challreason").clear() challreason.clear() challreason.send_keys("this is just wrong") self.browser.find_element_by_xpath("//input[@value='Challenge']").click() time.sleep(3) #target = self.browser.find_element_by_css_selector("#target") #self.assertIn('Challenge accepted', target.text) body = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_tag_name('body')) self.assertIn('Challenge accepted', body.text) self.url = ROOT + '/default/user/logout' get_browser=self.browser.get(self.url) time.sleep(1)
def test_login(self): driver = self.driver facebookUsername = "******" facebookPassword = "******" emailFieldID = "email" passFieldID = "pass" loginButtonXpath = "//input[@value='Zaloguj się']" fbLogoXpath = "//a[contains(@href,'https://www.facebook.com/?ref=logo')][1]" # Web driver bedzie czekal maksymalnie 10 sek na wyswietlenie emailField, jesli sie wyswietli to zapisze go do # FieldElement, jeśli nie, zwróci TimeOut exception emailFieldElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFieldElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_id(passFieldID)) loginButtonElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath((loginButtonXpath))) # czysci pole nazwy uzytkownika i wstawia tam dane ze zmiennej facebookUsername emailFieldElement.clear() emailFieldElement.send_keys(facebookUsername) # czysci pole hasla i wstawia tam dane ze zmiennej facebookPassword passFieldElement.clear() passFieldElement.send_keys(facebookPassword) # klikniecie przycisku logowania loginButtonElement.click() # oczekiwanie na wyswietlenie sie loga fb po zalogowaniu WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath((fbLogoXpath)))
def test_wp_login(self): driver = self.driver wp_username = '******' wp_password = '******' # pobiera kazdy element ze strony za pomoca xpath - odpowiednio: pole email, password, przycisk zaloguj i # przycisk odbierz - bedziemy sprawdzac, czy wieswietla sie po zalogowaniu emailFieldXpath = "//input[@name='login_username']" passFieldXpath = "//input[@name='login_password']" loginButtonXpath = "//input[@value='zaloguj']" odbierzButtonXpath = ".//*[@id='bxPanelTopBody']/div/div[1]/a[1]" # po wlaczeniu strony oczekuje sie wyswietlenia sie elementow, jesli nie wyswietla sie w 10 sekund - TimeOutExc. emailFieldElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath(emailFieldXpath)) passFieldElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath(passFieldXpath)) loginButtonElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath)) # czyszczenie pola email, wpisanie do niego danych emailFieldElement.clear() emailFieldElement.send_keys(wp_username) # czyszczenie pola password, wpisanie do niego danych passFieldElement.clear() passFieldElement.send_keys(wp_password) # klikniecie przycisku zaloguj loginButtonElement.click() #oczekiwanie na wyswietlenie sie danego elementu w celu sprawdzenia poprawnosci zalogowania WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath(odbierzButtonXpath))
def setHostname(self, name, desc): driver = self.driver hostname=name #Change to the Settings tab in a Microhard settingButtonXpath = "//a[@href='/cgi-bin/webif/system-settings.sh']" settingButtonEle = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(settingButtonXpath)) settingButtonEle.click() #Change Hostname Field hostnameFieldXpath = "//input[@name='hostname']" hostanmeFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(hostnameFieldXpath)) hostanmeFieldElement.clear() hostanmeFieldElement.send_keys(hostname) fieldXpath = "//input[@name='description']" fieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(fieldXpath)) fieldElement.clear() fieldElement.send_keys(desc) #Submit the change, like a commit commitFieldXpath = "//a[@href='#'][@id='waitbox']" commitFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(commitFieldXpath)) commitFieldElement.click()
def login(self, username, password, url=None): if url is not None: self.url = url driver = setup_webdriver() try: driver.get(self.url) driver.find_element_by_id("Email").clear() driver.find_element_by_id("Email").send_keys(username) try: driver.find_element_by_id("Passwd").clear() driver.find_element_by_id("Passwd").send_keys(password) except: driver.find_element_by_id("next").click() condition = EC.visibility_of_element_located((By.ID, "Passwd")) passwd = WebDriverWait(driver, 5).until(condition) passwd.clear() passwd.send_keys(password) driver.find_element_by_id("signIn").click() copy_cookies_to_session(driver, self) assert self.is_logged_in() except: driver.save_screenshot('/tmp/googlelogin_problem.png') raise finally: driver.quit()
def test_Login(self): #for i in range(0,846): driver = self.driver facebookUsername = LoginTest.mailData.pop() facebookPassword = LoginTest.passwordData.pop() emailFieldID = "email" passFieldID = "pass" loginButtonID = "loginbutton" loginButtonXpath = "//input[@value='Log In]" fbLogoXpath = "(//a[contains(@href, 'logo')])[1]" fbLogoId = "u_0_e" errorMessageClassName = 'pam login_error_box uiBoxRed' emailFieldElement = WebDriverWait(driver, 1).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFieldElement = WebDriverWait(driver, 1).until(lambda driver: driver.find_element_by_id(passFieldID)) loginButtonElement = driver.find_element_by_id(loginButtonID) emailFieldElement.clear() emailFieldElement.send_keys(facebookUsername) passFieldElement.clear() passFieldElement.send_keys(facebookPassword) #Check if can find fblogo button top left.If true user has logged in try: WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_id(fbLogoId)) except TimeoutException: print "Login failed" else: print "login successfull"
def test_Login(self): driver = self.driver # Facebook web element variables emailFieldID = "email" facebookUsername = "******" passFieldID = "pass" facebookPassword = "******" loginButtonXpath = "//input[@value='Log In']" fbLogoXpath = "(//a[contains(@href, 'logo')])[1]" # Create elements (allowing 10s to load) emailFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(passFieldID)) loginButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath)) # Actions: Log in emailFieldElement.clear() emailFieldElement.send_keys(facebookUsername) passFieldElement.clear() passFieldElement.send_keys(facebookPassword) loginButtonElement.click() # Verify successful login by locating fb logo WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(fbLogoXpath)) # Verify the actions visually time.sleep(3)
def test_Login(self) : driver = self.driver #initialize credentials fbFirstName = "" #PUT YOUR FIRST NAME fbLastName = "" #PUT YOUR LAST NAME emailOrMobileNo = "" #ENTER YOUR EMAIL ID fbPassword = "" #ENTER YOUR PASSWORD birthDay = "" #ENTER YOUR DAY OF BIRTH birthMonth = "" #ENTER YOUR MONTH OF BIRTH birthYear = "" #ENTER YOUR YEAR OF BIRTH sex = "" #ENTER YOUR SEX firstNameFieldId = "u_0_1" lastNameFieldId = "u_0_3" emailOrPhoneFieldId = "u_0_5" emailOrPhoneConfirmationFieldId = "u_0_8" passwordFieldId = "u_0_a" birthDayFieldId = "day" birthMonthFieldId = "month" birthYearFieldId = "year" maleSexFieldId = "u_0_d" femaleSexFieldId = "u_0_e" singUpButtonXpath = '//button[@id="u_0_i"]' fbWelcomePageIconXpath = '//a[contains(@href, "logo")]' firstNameFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(firstNameFieldId)) lastNameFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(lastNameFieldId)) emailOrPhoneFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(emailOrPhoneFieldId)) emailOrPhoneConfirmationFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(emailOrPhoneConfirmationFieldId)) passwordFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(passwordFieldId)) birthDayFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(birthDayFieldId)) birthMonthFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(birthMonthFieldId)) birthYearFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(birthYearFieldId)) maleSexFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(maleSexFieldId)) femaleSexFieldEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_id(femaleSexFieldId)) signUpButtonEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_xpath(singUpButtonXpath)) firstNameFieldEmerge.clear() firstNameFieldEmerge.send_keys(fbFirstName) lastNameFieldEmerge.clear() lastNameFieldEmerge.send_keys(fbLastName) emailOrPhoneFieldEmerge.clear() emailOrPhoneFieldEmerge.send_keys(emailOrMobileNo) emailOrPhoneConfirmationFieldEmerge.clear() emailOrPhoneConfirmationFieldEmerge.send_keys(emailOrMobileNo) passwordFieldEmerge.clear() passwordFieldEmerge.send_keys(fbPassword) Select(birthDayFieldEmerge).select_by_visible_text(birthDay) Select(birthMonthFieldEmerge).select_by_visible_text(birthMonth) Select(birthYearFieldEmerge).select_by_visible_text(birthYear) if(sex == "male") : maleSexFieldEmerge.click() else : femaleSexFieldEmerge.click() signUpButtonEmerge.click() fbIconEmerge = WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_xpath(fbWelcomePageIconXpath))
def _introduce_log_in_parameters(cls, username=FILAB2_MAIL, password=FILAB_PASSWORD): driver = cls.driver id_username = WebDriverWait(cls.driver, 10).until(EC.presence_of_element_located((By.ID, "id_email"))) id_username.clear() id_username.send_keys(username) driver.find_element_by_id("id_password").clear() driver.find_element_by_id("id_password").send_keys(password) driver.find_element_by_xpath("//button[@type='submit']").click() WebDriverWait(driver, 30).until(EC.staleness_of(id_username))
def type_user_name(self, user_name): """ This function gets the user id element and keys in the username that was requested :param user_name: user name that needs to be typed in :return None """ user_name_element = WebDriverWait(self.driver, 10).until( lambda driver: driver.find_element_by_id(self.user_name)) user_name_element.clear() # Clear contents in User ID text entry element user_name_element.send_keys(user_name) # Send keys with username that is defined by user
def preenche_frete_mercado_livre(): #elem_preco = WebDriverWait(driver, constants.SECONDS_OF_WAIT).until( # expected_conditions.presence_of_element_located(\ # (By.XPATH, constants.MERCADO_LIVRE_PRICE) # ) #) elem_calcular_frete = WebDriverWait(driver, constants.SECONDS_OF_WAIT).until( expected_conditions.presence_of_element_located(\ (By.XPATH, constants.MERCADO_LIVRE_CALCULATE_SHIPPING) ) ) elem_calcular_frete.click() elem_cep = WebDriverWait(driver, constants.SECONDS_OF_WAIT).until( expected_conditions.presence_of_element_located(\ (By.XPATH, constants.MERCADO_LIVRE_CEP_INPUT) ) ) elem_cep.clear() elem_cep.send_keys(constants.CEP) elem_cep_button = WebDriverWait(driver, constants.SECONDS_OF_WAIT).until( expected_conditions.presence_of_element_located(\ (By.XPATH, constants.MERCADO_LIVRE_CEP_BUTTON) ) ) elem_cep_button.click() elem_shipping_radio = WebDriverWait(driver, constants.SECONDS_OF_WAIT).until( expected_conditions.presence_of_element_located(\ (By.XPATH, constants.MERCADO_LIVRE_SHIPPING_RADIO) ) ) elem_shipping_radio.click() elem_aceitar_frete = WebDriverWait(driver, constants.SECONDS_OF_WAIT).until( expected_conditions.presence_of_element_located(\ (By.XPATH, constants.MERCADO_LIVRE_SHIPPING_ACCEPT_BUTTON) ) ) elem_aceitar_frete.click() elem_frete = WebDriverWait(driver, constants.SECONDS_OF_WAIT).until( expected_conditions.presence_of_element_located(\ (By.XPATH, constants.MERCADO_LIVRE_SHIPPING) ) ) return elem_frete
def test_(): rollbar.init(os.environ.get('rollbar')) email = os.environ.get('email') password = os.environ.get('password') assert email and password wait_time = int(os.environ.get('wait', default_wait)) try: options = webdriver.ChromeOptions() options.add_argument('--headless') driver = webdriver.Chrome(chrome_options=options) driver.get(renren) input_email = WebDriverWait(driver, wait_time).until( EC.presence_of_element_located((By.ID, 'email')) ) input_password = WebDriverWait(driver, wait_time).until( EC.presence_of_element_located((By.ID, 'password')) ) btn_login = WebDriverWait(driver, wait_time).until( EC.presence_of_element_located((By.ID, 'login')) ) input_email.clear() input_password.clear() input_email.send_keys(email) input_password.send_keys(password) driver.execute_script('arguments[0].click()', btn_login) btn_fortune = WebDriverWait(driver, wait_time).until( EC.presence_of_element_located((By.ID, 'assembleBtn')) ) driver.execute_script('arguments[0].click()', btn_fortune) popup = WebDriverWait(driver, wait_time).until( EC.visibility_of_element_located((By.ID, 'forPopupBox')) ) passed = popup.value_of_css_property('display') == 'block' if not passed: rollbar.report_message('Test Failed') assert passed except WebDriverException: rollbar.report_message('Test Errored') assert False else: rollbar.report_message('Test Passed') assert True finally: driver.quit()
def test_challenge(self): time.sleep(2) challreason = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_name("challreason")) #self.browser.find_element_by_name("challreason").clear() challreason.clear() challreason.send_keys("this is just wrong") self.browser.find_element_by_xpath("//input[@value='Challenge']").click() time.sleep(3) target = self.browser.find_element_by_css_selector("#target") self.assertIn('Challenge accepted', target.text)
def type_password(self, password): """ This function gets the password element and keys in the password that was requested :param password: password that needs to be typed in :return None """ password_element = WebDriverWait(self.driver, 10).until( lambda driver: driver.find_element_by_id(self.password_field)) password_element.clear() # Clear contents in Password text entry element password_element.send_keys(password) # Send keys with password that is defined by user
def input(self,driver,xpath,value,param): if param: #import pdb;pdb.set_trace() xpath = xpath % param element = WebDriverWait(driver, TIME_OUT).until(EC.visibility_of_element_located((By.XPATH, xpath))) time.sleep(1) #text = element.text #if text: element.clear() time.sleep(0.5) element.send_keys(value) time.sleep(1)
def test_Login(self): os.system("say i am at login page!") driver = self.driver facebookUserName = "******" facebookPassword = "******" emailFieldID = "email" passwordFieldID = "pass" loginButtonXPath = "//input[@value='Log In']" notificationButtonXpath = "//a[@name='notifications']" fbLogoXPath = "(//a[contains(@href,'logo')])[1]" emailFieldElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFieldElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_id(passwordFieldID)) loginButtonElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath (loginButtonXPath)) emailFieldElement.clear() emailFieldElement.send_keys(facebookUserName) passFieldElement.clear() passFieldElement.send_keys(facebookPassword) loginButtonElement.click() os.system("say i filled login page") #WebDriverWait(driver,20).until(lambda driver: driver.find_element_by_xpath (fbLogoXPath)) #notificationButtonElement = WebDriverWait(driver,10).until(lambda driver: driver.find_element_by_xpath (notificationButtonXpath)) #notificationButtonElement.click() html_source = driver.page_source #print html_source os.system("say now, i am in!") matchObj = re.search('id="notificationsCountValue">(.)', html_source, re.M|re.I) MessageObj = re.search('id="mercurymessagesCountValue">(.)', html_source, re.M|re.I) RequestObj = re.search('id="requestsCountValue">(.)', html_source, re.M|re.I) if matchObj: print "match: ", matchObj.group(1) os.system("say you have "+matchObj.group(1)+" notifications") os.system("say "+MessageObj.group(1)+" messages") os.system("say and "+RequestObj.group(1)+" friends request") else: print "No match!!" os.system("say problem")
def verify_username(username): login_field = WebDriverWait(driver, 60).until( EC.element_to_be_clickable((By.ID, 'identifierId'))) while True: # Enters username and clicks next button login_field.send_keys(username) driver.find_element_by_id('identifierNext').click() try: # Checks for invalid username warning warning = WebDriverWait(driver, 3).until( EC.visibility_of_element_located(( By.XPATH, '//*[@id="view_container"]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div/div[2]/div[2]' ))) if warning: print(colored('Warning! Google Account not found.', 'red')) username = get_google_username() login_field.clear() continue except (TimeoutException): print(colored('Username verified.', 'green')) break
def testShouldNotSwitchMagicallyToTheTopWindow(self, driver, pages): pages.load("frame_switching_tests/bug4876.html") driver.switch_to.frame(0) WebDriverWait(driver, 3).until( EC.presence_of_element_located((By.ID, "inputText"))) for i in range(20): try: input = WebDriverWait(driver, 3).until( EC.presence_of_element_located((By.ID, "inputText"))) submit = WebDriverWait(driver, 3).until( EC.presence_of_element_located((By.ID, "submitButton"))) input.clear() import random input.send_keys("rand%s" % int(random.random())) submit.click() finally: url = driver.execute_script("return window.location.href") # IE6 and Chrome add "?"-symbol to the end of the URL if (url.endswith("?")): url = url[:len(url) - 1] assert pages.url("frame_switching_tests/bug4876_iframe.html") == url
def test_login(self): driver = self.driver username = "******" password = "******" emailFieldID = "email" passFeildID = "pass" loginButtonXpath = "//input[@value = 'Log In']" emailFieldElement = WebDriverWait( driver, 10).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFeildElement = WebDriverWait( driver, 10).until(lambda driver: driver.find_element_by_id(passFeildID)) loginButtonElement = WebDriverWait(driver, 10).until( lambda driver: driver.find_element_by_id(loginButtonXpath)) emailFieldElement.clear() emailFieldElement.send_keys(username) passFeildElement.clear() passFeildElement.send_keys(password) loginButtonElement.click()\
def get_login_btn(self): # 打开网址 self.driver.get("https://passport.bilibili.com/login") username = WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located((By.ID, 'login-username'))) username.clear() username.send_keys(self.USERNAME) time.sleep(2) pwd = WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located((By.ID, 'login-passwd'))) pwd.clear() pwd.send_keys(self.PASSWARD) time.sleep(2) # 点击登录,弹出滑块验证码 login_btn = WebDriverWait(self.driver, 10, 0.5).until( EC.element_to_be_clickable( (By.XPATH, '//*[@class="btn-box"]//a[@class="btn btn-login"]'))) login_btn.click() WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located( (By.CLASS_NAME, 'geetest_slider_button')))
def test_Login(self): driver = self.driver lmsUsername = "******" lmsPassword = "******" emailFieldID = "email" passFieldID = "password" LoginButtonXpath = "//input[@value='登入']" emailFieldElement = WebDriverWait(driver, 10).until(lambda drivers: drivers.find_element_by_id(emailFieldID)) passFieldElement = WebDriverWait(driver, 10).until(lambda drivers: drivers.find_element_by_id(passFieldID)) loginButtonElement = WebDriverWait(driver, 10).until(lambda drivers: drivers.find_element_by_xpath(LoginButtonXpath)) emailFieldElement.clear() emailFieldElement.send_keys(lmsUsername) passFieldElement.clear() passFieldElement.send_keys(lmsPassword) time.sleep(5) loginButtonElement.click() time.sleep(60) assert "课程安排" in driver.page_source driver.get_screenshot_as_file('/Users/wg/Desktop/pic/foo.png')
def next_page(page_number): try: input = WebDriverWait(browser, 10).until( EC.presence_of_element_located( (By.CSS_SELECTOR, "#mainsrp-pager > div > div > div > div.form > input"))) submit = WebDriverWait(browser, 10).until( EC.element_to_be_clickable(( By.CSS_SELECTOR, '#mainsrp-pager > div > div > div > div.form > span.btn.J_Submit' ))) input.clear() input.send_keys(page_number) submit.click() WebDriverWait(browser, 10).until( EC.text_to_be_present_in_element(( By.CSS_SELECTOR, '#mainsrp-pager > div > div > div > ul > li.item.active > span' ), str(page_number))) get_products() except TimeoutException: print('超时啦.............') next_page(page_number)
def get_all_page(self, page): """ 对每一个的token进行获取与请求 :param page: 当前页数 :return: """ next = WebDriverWait(self.webdir, 15).until(EC.presence_of_element_located( (By.XPATH, './/div[@class="ivu-page-options-elevator"]/input[@type="text"]'))) next.clear() next.send_keys(page) next.send_keys(Keys.ENTER) token_list_content = self.analysis_token_list() for i in range(1, 51): # 每一页的最大条数 try: WebDriverWait(self.webdir, 15).until(EC.presence_of_element_located((By.XPATH, './/tbody[@class="ivu-table-tbody"]/tr[{}]'.format(i)))).click() handles = self.webdir.window_handles # 获取当前全部窗口句柄集合 self.webdir.switch_to.window(handles[1]) # 切换到第二个窗口 self.webdir.close() # 关闭第二个窗口 self.webdir.switch_to.window(handles[0]) # 切换到第一个窗口 except: print('没有此页面') pass
def function_login(): Username = '******' Password = '******' #For finding the username textfield and password textfield using xpath emailFieldID = 'username' passFieldID = 'pwd' loginButtonpath = '//*[@id="login-button"]' #Find elements for login purpose and sends username and password in the textfield and find login button and clicks on it emailFieldElem = WebDriverWait( driver, 1).until(lambda driver: driver.find_element_by_id(emailFieldID)) passFieldElem = WebDriverWait( driver, 1).until(lambda driver: driver.find_element_by_id(passFieldID)) loginButtonElem = WebDriverWait( driver, 1).until(lambda driver: driver.find_element_by_xpath(loginButtonpath)) emailFieldElem.clear() emailFieldElem.send_keys(Username) passFieldElem.clear() passFieldElem.send_keys(Password) loginButtonElem.click()
def _login(self): """ Logs into the provided Clever instance. """ self.log.info('Logging into Clever instance: hostname, username: {}, {}'.format( self.hostname, self.username )) self.driver.get(self.base_url) # wait until login form available elem = WebDriverWait(self.driver, self.wait_time).until( EC.presence_of_element_located((By.NAME, 'username'))) elem.clear() elem.send_keys(self.username) elem = self.driver.find_element_by_name("password") elem.send_keys(self.password) elem.send_keys(Keys.RETURN) # ensure that login is successful self.driver.get(self.base_url) if 'Clever | Home' not in self.driver.title: self.driver.close() raise InvalidLoginCredentials
def do_search(driver: WebDriver, search_term: str) -> List[ClickableVideoElement]: """ Search youtube for the search_term and return the results """ # Input the search term and confirm search_box = WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.CSS_SELECTOR, "input#search"))) assert "Search" in search_box.get_attribute("placeholder") search_box.clear() search_box.send_keys(search_term) WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.ID, 'search-icon-legacy'))).click() # Wait for results page to load WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.TAG_NAME, "ytd-video-renderer"))) # Get all results video_title_elems = driver.find_elements_by_tag_name("ytd-video-renderer") videos = [] for element in video_title_elems: if not is_livestream(element): videos.append(ClickableVideoElement(element)) return videos
def _login(self): """ Logs into the provided Lexia instance. """ login_url = self.uri_scheme + 'auth.mylexia.com/mylexiaLogin' self.log.debug('Logging into Lexia at: {}'.format(login_url)) self.driver.get(login_url) elem = WebDriverWait(self.driver, self.wait_time).until( EC.presence_of_element_located((By.ID, 'username'))) elem.clear() elem.send_keys(self.username) elem.send_keys(Keys.RETURN) elem = WebDriverWait(self.driver, self.wait_time).until( EC.presence_of_element_located((By.ID, 'login-password'))) elem.send_keys(self.password) elem.send_keys(Keys.RETURN) # ensure that login is successful self.driver.get(self.base_url) if 'Welcome' in self.driver.title: self.driver.close() raise InvalidLoginCredentials
def answerForm1(self): try: #Here we need to account for different application windows time.sleep(1) try: phone_input = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located( (By.ID, 'apply-form-phone-input'))) phone_input.clear() phone_input.send_keys(self.phone) time.sleep(1) except Exception as e: print(str(e)) try: resumeBtn = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located( (By.ID, 'file-browse-input'))) resumeBtn.send_keys(self.resumeLocation) time.sleep(1) except Exception as e: print(str(e)) try: form_submit_btn = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located( (By.CLASS_NAME, 'jobs-apply-form__submit-button'))) form_submit_btn.click() except Exception as e: print(str(e)) print("Successfully applied to job!") time.sleep(3) except: print("Primary Form Invalid. Switching to secondary....") self.answerForm2()
def signin(): # def NCookie(): # if os.path.exists("jar.pkl"): # wCookie() # else: # open("jar.pkl","wb") # print("""file did not existed !!! # and it is created now # repeat the process to handle the file""") # wCookie() # def wCookie(): # if os.path.getsize("jar.pkl")==0: driver.get("https://accounts.google.com") enames = ['identifier', 'Email'] for name in enames: try: mail = driver.find_element_by_name(name) if mail: mail.clear() mail.send_keys(os.getenv("USERNAME")) mail.send_keys(Keys.RETURN) except Exception as err: print(err) pnames = ['Passwd', 'password'] for name in pnames: try: paswd = WebDriverWait(driver, 15).until( EC.visibility_of_element_located((By.NAME, "password"))) if paswd: paswd.clear() paswd.send_keys(os.getenv("PASSWORD")) paswd.send_keys(Keys.RETURN) time.sleep(6) except Exception as err: print(err)
def login(number, password): try: click_login = WD(browser, 60).until( EC.element_to_be_clickable( (By.XPATH, '//*[@id="main"]/div/div[2]/div[1]/div/div[1]/div/ul/a[2]'))) browser.execute_script("arguments[0].click();", click_login) except NoSuchElementException as a: print(a) time.sleep(5) try: number_input = WD(browser, 60).until( EC.element_to_be_clickable((By.NAME, 'loginKey'))) browser.execute_script("arguments[0].click();", number_input) number_input.clear() number_input.send_keys(ac.email_phone_number) pass_input = WD(browser, 60).until( EC.element_to_be_clickable((By.NAME, 'password'))) browser.execute_script("arguments[0].click();", pass_input) pass_input.clear() pass_input.send_keys(ac.passwd) enter = WD(browser, 60).until( EC.element_to_be_clickable( (By.XPATH, '//*[@id="main"]/div/div[2]/div/div/form/div/div[2]/button'))) browser.execute_script("arguments[0].click();", enter) except NoSuchElementException as e: print(e) try: click_login_button = WD(browser, 60).until( EC.element_to_be_clickable( (By.XPATH, '//*[@id="modal"]/aside/div[1]/div/div[2]/button[2]'))) browser.execute_script("arguments[0].click();", click_login_button) except NoSuchElementException as e: print(e) time.sleep(10)
def test_diff_texts(self): driver = self.start_test(target=diff_texts_thread) elem = WebDriverWait(driver, TIMEOUT).until( EC.presence_of_element_located( (By.CSS_SELECTOR, ".input_interface[interface_id='0'] .input_text"))) elem.clear() elem.send_keys("Want to see a magic trick?") elem = WebDriverWait(driver, TIMEOUT).until( EC.presence_of_element_located( (By.CSS_SELECTOR, ".input_interface[interface_id='1'] .input_text"))) elem.clear() elem.send_keys("Let's go see a magic trick!") elem = WebDriverWait(driver, TIMEOUT).until( EC.presence_of_element_located((By.CSS_SELECTOR, ".submit"))) elem.click() elem = WebDriverWait(driver, TIMEOUT).until( EC.presence_of_element_located( (By.CSS_SELECTOR, ".output_interface[interface_id='2'] .output_text"))) total_sleep = 0 while elem.text == "" and total_sleep < TIMEOUT: time.sleep(0.2) total_sleep += 0.2 self.assertEqual(elem.text, "LeWant's tgo see a magic trick?!") golden_img = os.path.join( current_dir, GOLDEN_PATH.format("diff_texts", "magic_trick")) tmp = os.path.join(current_dir, "test/tmp/{}.png".format(random.getrandbits(32))) hide_latency(driver) driver.save_screenshot(tmp) driver.close() self.assertIsNone(compare_images(tmp, golden_img, TOLERANCE)) os.remove(tmp)
def form_filling(page_1, email, count, arr_len, price): congrats = "Congrats on winning!! Thanks for using the BAND App!" message_area = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located((By.XPATH, '//*[@id="message"]'))) message_area.send_keys(congrats) price_button = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located((By.XPATH, '//*[@id="pre_range"]/p'))) price_button.click() price_area = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located((By.XPATH, '//*[@id="amount"]'))) price_area.clear() price_area.send_keys(price) name_area = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located((By.XPATH, '//*[@id="sender_name"]'))) name_area.send_keys(NAME) my_email_area = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located( (By.XPATH, '//*[@id="sender_email"]'))) my_email_area.send_keys(NAVER_EMAIL) user_email_area = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located( (By.XPATH, '//*[@id="recipient_email"]'))) user_email_area.send_keys(email) sleep(1) # PUT A CONDITIONS HERE BASED ON ARRAY LENGTH add_cart_button = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located( (By.XPATH, '//*[@id="ecardform"]/div[3]/span/button'))) add_cart_button.click() if count != (arr_len - 1): keep_Shopping(page_1) # USING 'CSS_SELECTOR' BELOW BECAUSE XPATH WAS CHANGING WHEN WEBSITE ADDED AND DELETED CERTAIN GIFT CARD OPTIONS workplace_button = WebDriverWait(page_1, TIMEOUT).until( EC.visibility_of_element_located( (By.CSS_SELECTOR, "a[href='/shop/card/egift/workplace']"))) workplace_button.click()
def __sendMsg__(browser, groups, msg): for group in groups: search_xpath = '//div[@contenteditable="true"][@data-tab="3"]' search_box = WebDriverWait(browser, 500).until( EC.presence_of_element_located((By.XPATH, search_xpath))) # '//*[@id="side"]/div[1]/div/label/div/div[2]'' search_box.clear() time.sleep(1) pyperclip.copy(group) search_box.send_keys(Keys.SHIFT, Keys.INSERT) # Keys.CONTROL + "v" time.sleep(2) try: group_xpath = f'//span[@title="{group}"]' group_title = browser.find_element_by_xpath(group_xpath) group_title.click() time.sleep(1) input_xpath = '//div[@contenteditable="true"][@data-tab="6"]' input_box = browser.find_element_by_xpath(input_xpath) pyperclip.copy(msg.format(group.split()[0])) input_box.send_keys(Keys.SHIFT, Keys.INSERT) # Keys.CONTROL + "v" input_box.send_keys(Keys.ENTER) time.sleep(2) except Exception as e: logging.info(e)
def test_put_values_in_regester_form(self, user, passwd): first_name = WebDriverWait(self, 10).until(lambda self: self.browser.find_element_by_name("first_name")) first_name.clear() first_name.send_keys(user) last_name = self.browser.find_element_by_name("last_name") last_name.clear() last_name.send_keys(user) mailstring = user+'@user.com' # if user == 'Testuser2': # mailstring = '*****@*****.**' email = self.browser.find_element_by_name("email") email.clear() email.send_keys(mailstring) password = self.browser.find_element_by_name("password") password.clear() password.send_keys(passwd) verify_password = self.browser.find_element_by_name("password_two") verify_password.clear() verify_password.send_keys(passwd) time.sleep(1) register_button = self.browser.find_element_by_css_selector("#submit_record__row input") time.sleep(1) register_button.click() resultstring = 'Welcome ' + user time.sleep(1) body = WebDriverWait(self, 10).until(lambda self: self.browser.find_element_by_tag_name('body')) self.assertIn(resultstring, body.text) self.url = ROOT + '/default/user/logout' get_browser = self.browser.get(self.url) time.sleep(1)
def _dead_code(self): # web driver wait element = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.ID, "button-top-ban-send-money"))) sleep(2) element.click() sleep(2) type_ahead = WebDriverWait(self.driver, 5).until( EC.element_to_be_clickable((By.ID, "country"))) sleep(2) ele = self.driver.find_element_by_xpath('//*[@id="top-country-tile"]/div/button[3]') sleep(1) ele.click() sleep(10) if False: ele = self.driver.find_element_by_xpath("//div[@role='search']") sleep(2) ele.click() type_ahead.send_keys(Keys.NULL) # type_ahead.click() sleep(2) type_ahead.clear() sleep(2) type_ahead.send_keys("India") # sleep(2) # type_ahead.send_keys(Keys.ARROW_DOWN) items = self.driver.find_elements_by_xpath( '//*[@id="smonewuser"]/div/app-sendmoney-option/div[2]/div[1]/div/div/form/app-country-dropdown/div[1]/ul/li/a') for item in items[1:2]: print(item) print(item.text) item.click()
def test_get_todo_list(self): # setup self.driver.get('https://www.python.org/') assert 'Python' in self.driver.title self.driver.find_element_by_link_text('Downloads').click() element = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, '.download-list-widget .widget-title'))) assert 'Looking for a specific release?' == element.text self.driver.find_element_by_link_text('Documentation').click() element = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located((By.CLASS_NAME, 'call-to-action'))) assert 'Browse the docs' in element.text element = self.driver.find_element_by_name('q') element.clear() element.send_keys('pycon') element.send_keys(Keys.RETURN) assert 'No results found' not in self.driver.page_source
def geo(): geography_handle.click() geo_searched_region1 = 'Malaysia' geo_searched_region2 = 'Singapore' geo_enter = WebDriverWait(driver,5).until( EC.presence_of_element_located((By.CLASS_NAME,'text-input--no-border.mb4.ember-text-field.ember-view'))) geo_enter.clear() geo_enter.send_keys(geo_searched_region1) time.sleep(1) geo1 = driver.find_elements_by_class_name("button--unstyled.link-without-visited-state.t-14.font-weight-400.cursor-pointer.search-filter-typeahead__suggestion-item-value.text-align-left") geo1[0].click() # Entering second location geo_enter.clear() geo_enter.send_keys(geo_searched_region2) time.sleep(0.5) geo1 = driver.find_elements_by_class_name("button--unstyled.link-without-visited-state.t-14.font-weight-400.cursor-pointer.search-filter-typeahead__suggestion-item-value.text-align-left") geo1[0].click() time.sleep(0.5)
def login(self, driver): fb_username = input( "Enter your Facebook username: "******"Enter your Facebook password: "******"email" passwordFieldName = "pass" loginButtonXpath = '//input[@value="Log In"]' email_elem = WebDriverWait( driver, 10).until(lambda driver: driver.find_element_by_id(emailFieldName)) password_elem = WebDriverWait(driver, 10).until( lambda driver: driver.find_element_by_id(passwordFieldName)) login_button_elem = WebDriverWait(driver, 10).until( lambda driver: driver.find_element_by_xpath(loginButtonXpath)) email_elem.clear() email_elem.send_keys(fb_username) password_elem.clear() password_elem.send_keys(fb_password) print("Logging in Now ... ") login_button_elem.click()
def login(self): bot = self.bot bot.get("https://www.instagram.com/accounts/login/") try: email = WebDriverWait(bot, 10).until( EC.presence_of_element_located((By.NAME, "username"))) finally: email = bot.find_element_by_name("username") email.clear() email.send_keys(self.email) try: password = WebDriverWait(bot, 10).until( EC.presence_of_element_located((By.NAME, "password"))) finally: password = bot.find_element_by_name("password") password.clear() password.send_keys(self.password) password.send_keys(Keys.RETURN) try: notifications = WebDriverWait(bot, 10).until( EC.presence_of_element_located((By.CLASS_NAME, "HoLwm"))) finally: notifications = bot.find_element_by_class_name("HoLwm") notifications.click()
def testShouldNotSwitchMagicallyToTheTopWindow(self): baseUrl = self.webserver.where_is("frame_switching_tests/") self.driver.get(baseUrl + "bug4876.html") self.driver.switch_to.frame(0) WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "inputText"))) for i in range(20): try: input = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "inputText"))) submit = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "submitButton"))) input.clear() import random input.send_keys("rand%s" % int(random.random())) submit.click() finally: url = self.driver.execute_script("return window.location.href") # IE6 and Chrome add "?"-symbol to the end of the URL if (url.endswith("?")): url = url.substring(0, url.length() - 1) self.assertEquals(baseUrl + "bug4876_iframe.html", url)
def enter_credentials(self): try: usernameField = WebDriverWait(self.driver, 10).until( ec.presence_of_element_located((By.NAME, 'username'))) usernameField.clear() usernameField.send_keys(self.credentials.get('username')) passwordField = WebDriverWait(self.driver, 10).until( ec.presence_of_element_located((By.NAME, 'password'))) passwordField.clear() passwordField.send_keys(self.credentials.get('password')) passwordField.send_keys(Keys.ENTER) #wait 3 seconds for the passwordfield to stop being attached to the DOM staleness = WebDriverWait(self.driver, 5).until(ec.staleness_of(passwordField)) #whether to continue, as it would produce an error if it tried to use webdriver and it quit return True except (exceptions.NoSuchElementException, exceptions.TimeoutException): print('Unable to enter credentials') self.driver.quit() return False
def getMapOver525(query, locationQuery, city): global driver global delay global count_start global count_end global store_infos driver.get("http://map.daum.net") try: elem = WebDriverWait(driver, delay).until( EC.presence_of_element_located((By.NAME, 'q'))) except TimeoutException: print("Loading took too much time!") finally: elem.clear() elem.send_keys(locationQuery) elem.send_keys(Keys.RETURN) time.sleep(1) _html = driver.page_source soup = BeautifulSoup(_html, "lxml") count = soup.find("em", id="info.search.place.cnt") if count.text != '': total_data_count = int(count.text) else: total_data_count = 0 #지역명 + 상호명 일 때는 2페이지부터 보여줌으로 한번 긁고 시작해야한다! crawlList(query, city) try: clickElem = WebDriverWait(driver, delay) \ .until(EC.presence_of_element_located((By.ID, "info.search.place.more"))) clickElem.click() time.sleep(1) except TimeoutException: print("Loading took too much time!") finally: return total_data_count
def test_Login(self): driver = self.driver user_name = "............" user_pass = "******" emailFieldXpath = '//input[@id="MainLogin_UserName"]' passFieldXpath = '//input[@id="MainLogin_Password"]' loginButtonXpath = '//input[@id="MainLogin_CtrlLoginButton"]' emailFieldElement = WebDriverWait(driver, 10).until( lambda driver: driver.find_element_by_xpath(emailFieldXpath)) passFieldElement = WebDriverWait(driver, 10).until( lambda driver: driver.find_element_by_xpath(passFieldXpath)) loginButtonElement = WebDriverWait(driver, 10).until( lambda driver: driver.find_element_by_xpath(loginButtonXpath)) emailFieldElement.clear() emailFieldElement.send_keys(user_name) passFieldElement.clear() passFieldElement.send_keys(user_pass) loginButtonElement.click() self.driver.quit()
def send_price(names, prices): for name in names: # search_box = WebDriverWait(driver, 100).until(EC.presence_of_element_located( # (By.XPATH, '//div[@contenteditable="true"][@data-set="3"]'))) search_box = WebDriverWait(driver, 100).until( EC.presence_of_element_located( (By.XPATH, '//div[@class="_2_1wd copyable-text selectable-text"]'))) # search_box = driver.find_element_by_xpath('//div[@contenteditable="true"][@data-set="3"]') # search_box = driver.find_element_by_xpath('//div[@class="_2_1wd.copyable-text.selectable-text"]') pyperclip.copy(name) search_box.send_keys(Keys.CONTROL + "v") group = WebDriverWait(driver, 100).until( EC.presence_of_element_located( (By.XPATH, '//span[@title = "{}"]'.format(name)))) group.click() # print('Whatsapp group found') msg_box = WebDriverWait(driver, 100).until( EC.presence_of_element_located( (By.XPATH, '//div[@contenteditable="true"][@data-tab="6"]'))) msg_box.clear() pyperclip.copy(prices) msg_box.send_keys(Keys.CONTROL + "v") msg_box.send_keys(Keys.ENTER)
def participate(self): """Finish reading and send text""" try: logger.info("Entering participate method") ready = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.ID, "finish-reading"))) stimulus = self.driver.find_element_by_id("stimulus") story = stimulus.find_element_by_id("story") logger.info("Stimulus text:") logger.info(story) ready.click() submit = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.ID, "submit-response"))) textarea = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.ID, "reproduction"))) textarea.clear() text = story logger.info("Transformed text:") logger.info(text) textarea.send_keys(text) submit.click() return True except TimeoutException: return False
def test_login(keys_username, keys_password): driver.get("http://127.0.0.1:8000/logout/") try: # username input_username = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.NAME, "username"))) input_username.clear() input_username.send_keys(keys_username) # password input_password = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.NAME, "password"))) input_password.clear() input_password.send_keys(keys_password) # press enter input_password.send_keys(Keys.RETURN) # print statements print("keys_username: "******"keys_password: "******"SingHealth WebApp"): isValid = True print("TESTCASE: VALID! LOGGED IN ✓") else: isValid = False print("TESTCASE: FAILED, CANNOT LOG IN") print() time.sleep(waitTime) except: print("TEST FAILED TO RUN") time.sleep(5) driver.quit()