def test_blog(self): user = "******" pwd = "instructor1a" driver = self.driver driver.maximize_window() driver.get("http://127.0.0.1:8000/admin") elem = driver.find_element_by_id("id_username") elem.send_keys(user) elem = driver.find_element_by_id("id_password") elem.send_keys(pwd) elem.send_keys(Keys.RETURN) driver.get("http://127.0.0.1:8000/home") assert "Logged In" time.sleep(5) elem = driver.find_element_by_xpath( "html/body/div/div/div/div[2]/div/div/div/div/div[3]/div/div/p[2]/a" ).click() time.sleep(5) elem = driver.find_element_by_xpath( "html/body/div/div/div/div[3]/div/a/span").click() time.sleep(5) elem = Select(driver.find_element_by_id('id_cust_name')) elem.select_by_visible_text('Lillian Wells') elem = driver.find_element_by_id("id_product") elem.send_keys("Taffy") elem = driver.find_element_by_id("id_p_description") elem.send_keys("Cherry and Lemonade") elem = driver.find_element_by_id("id_quantity") elem.send_keys("124") elem = driver.find_element_by_id("id_charge") elem.send_keys("36.48") time.sleep(5) elem.send_keys(Keys.RETURN) assert "Posted Product Entry" driver.get("http://127.0.0.1:8000/product_list")
def registration_new_customer(self): LogFile.logger.info('Registration new customer.') element = self.element_to_be_present(*RegNewCustomer.CREATE_ACC) # Generates different email element.send_keys(str(time.time()) + '@fakemail.org') element = self.browser.find_element(*RegNewCustomer.CREATE_SUBMIT_BTN) element.click() # Fill up ONLY required field element = self.element_to_be_present(*RegNewCustomer.FIRST_NAME) element.send_keys('Vladyslav') element = self.browser.find_element(*RegNewCustomer.LAST_NAME) element.send_keys('Shevchenko') element = self.browser.find_element(*RegNewCustomer.PASSWD) element.send_keys('46464rte.1!@fdfs') element = self.browser.find_element(*RegNewCustomer.ADRESS) element.send_keys('Odessa') element = self.browser.find_element(*RegNewCustomer.CITY) element.send_keys('Odessa') element = Select(self.browser.find_element(*RegNewCustomer.STATE)) element.select_by_value('2') element = self.browser.find_element(*RegNewCustomer.POSTCODE) element.send_keys('65000') element = self.browser.find_element(*RegNewCustomer.PHONE_NUMBER) element.send_keys('1234567890') element = self.browser.find_element(*RegNewCustomer.SUMBIT_BTN) element.click() element = self.browser.find_element(*RegNewCustomer.CHECKOUT_BTN) element.click() time.sleep(Env.vars['wait_time']) LogFile.logger.info('Registration is complete.')
def test_Admin_candidate_creation(self): driver = self.driver driver.get("http://*****:*****@gmail.com" + Keys.TAB + "qwerty1234" + Keys.TAB + Keys.ENTER) user = driver.find_element_by_id("createcandidate") user.send_keys(Keys.ENTER) user = driver.find_element_by_name("firstname") user.send_keys("test-firstname") user = driver.find_element_by_name("lastname") user.send_keys("test-lastname") user = Select(driver.find_element_by_name('party')) user.select_by_value("democrats") user = Select(driver.find_element_by_name('electionID')) user.select_by_value("987346") user = Select(driver.find_element_by_name('precinct')) user.select_by_value("precinct1") user = Select(driver.find_element_by_name('position')) user.select_by_value("city representative") user = driver.find_element_by_id("finalsubmit") user.send_keys(Keys.ENTER) assert "Candidate Creation" in driver.page_source
def test_mark_attendance(self): user = "******" pwd = "arti12345" driver = self.driver driver.maximize_window() driver.get("https://omk-2.herokuapp.com/login_user/") elem = driver.find_element_by_id("id_username") elem.send_keys(user) elem = driver.find_element_by_id("id_password") elem.send_keys(pwd) elem.send_keys(Keys.RETURN) assert "Logged In" #time.sleep(5) #Mark Attendance elem = driver.find_element_by_xpath( "/html/body/div[1]/nav/div[2]/ul/li[2]/a").click() elem = driver.find_element_by_xpath( "/html/body/div[1]/div/div/div/div/div/table/tbody/tr[1]/td[3]/a" ).click() #elem = driver.find_element_by_name("stu_name").click() elem = Select(driver.find_element_by_id("id_stu_name")) elem.select_by_value("2") elem = driver.find_element_by_id("id_attend").click() elem = driver.find_element_by_id("id_remarks") elem.clear() elem.send_keys("This is test Attendance") elem = driver.find_element_by_xpath( "/html/body/div[1]/div/div/form/button").click() # Click Student List elem = driver.find_element_by_xpath( "/html/body/div[1]/nav/div[2]/ul/li[3]/a").click()
def main(): driver = webdriver.Chrome() driver.get("http://localhost/litecart/en/") wait = WebDriverWait(driver, 10) # seconds wait.until(EC.title_contains("My Store")) try: form = driver.find_element_by_name("login_form") a = form.find_element_by_tag_name("a") a.click() wait.until(EC.title_contains("My Store")) driver.find_element_by_name("firstname").send_keys("ivan") driver.find_element_by_name("lastname").send_keys("ivanov") driver.find_element_by_name("address1").send_keys("Trump ave 1") driver.find_element_by_name("postcode").send_keys("".join( random.sample("0123456789", 5))) driver.find_element_by_name("city").send_keys("Atlanta") country = driver.find_element_by_name("country_code") elm = Select(country) elm.select_by_visible_text("United States") zone = wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, "select[name=zone_code]"))) elm = Select(zone) zones_total = len(elm.options) elm.select_by_index(random.randint(0, zones_total - 1)) elm = driver.find_element_by_name("email") email = "".join(random.sample("abcdefghijklABCDEFGHIGKL12345", 10)) + "@example.com" elm.send_keys(email) driver.find_element_by_name("phone").send_keys( "+1" + "".join(random.sample("0123456789", 7))) driver.find_element_by_name("password").send_keys("1") driver.find_element_by_name("confirmed_password").send_keys("1") driver.find_element_by_name("create_account").click() wait.until(EC.title_contains("My Store")) logout(driver, wait) driver.find_element_by_name("email").send_keys(email) driver.find_element_by_name("password").send_keys("1") driver.find_element_by_name("login").click() wait.until(EC.title_contains("My Store")) logout(driver, wait) print("Успешно") finally: driver.close()
def test_log(self): driver = self.driver driver.maximize_window() driver.get("http://onspar.pythonanywhere.com/login") driver.find_element_by_xpath("/html/body/div[2]/a[3]").click() elem = driver.find_element_by_name("login") elem.clear() elem.send_keys("vasuparikh") time.sleep(6) elem = driver.find_element_by_name("password") elem.clear() elem.send_keys("vasu95guy") driver.find_element_by_xpath("/html/body/div[3]/div[1]/div/form/div[2]/input[3]").click() time.sleep(7) driver.find_element_by_xpath("/html/body/nav/div/div/ul[1]/li[2]/a").click() time.sleep(3) driver.find_element_by_xpath("/html/body/div[3]/div[1]/a[2]").click() time.sleep(20) elem = Select(driver.find_element_by_id("id_quantity")) elem.select_by_value("2") driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/div[2]/div/div/form/div/div/button").click() time.sleep(5) driver.find_element_by_xpath("/html/body/ul/li[2]/a").click() time.sleep(5) driver.find_element_by_xpath("/html/body/div[2]/a").click() time.sleep(10) driver.find_element_by_xpath("/html/body/form/input[12]").click() time.sleep(15) elem = driver.find_element_by_name("login_email") elem.clear() elem.send_keys("*****@*****.**") time.sleep(15) elem = driver.find_element_by_id("btnNext") elem.click() time.sleep(10) elem = driver.find_element_by_name("login_password") elem.clear() elem.send_keys("test1234") time.sleep(15) elem = driver.find_element_by_id("btnLogin") elem.click() time.sleep(7) elem = driver.find_element_by_id("confirmButtonTop") elem.click() time.sleep(17) elem = driver.find_element_by_id("merchantReturnBtn") elem.click() time.sleep(7) def tearDown(self): self.driver.close()
def filter(self, name, value): """filters the table by using value for the column specified by name. Note that this abstracts the different ways filter controls can be implemented. """ filter_ = self.e.find_element_by_id('dt-filter-%s' % name) if filter_.find_elements_by_tag_name('option'): filter_ = Select(filter_) filter_.select_by_visible_text(value) else: filter_.send_keys(value) time.sleep(2.5)
def filter(self, name, value): """filters the table by using value for the column specified by name. Note that this abstracts the different ways filter controls can be implemented. """ filter_ = self.e.find_element_by_id('dt-filter-%s' % name) if filter_.find_elements_by_tag_name('option'): filter_ = Select(filter_) filter_.select_by_visible_text(value) else: filter_.send_keys(value) time.sleep(2.5)
def create_all_fees(driver, contributions): """Create all fee disbursements in ActBlue contributions. ONLY RUN THIS ONCE per line.""" actblue = 'ActBlue Techincal Services' if not entity_exists(driver, actblue): create_actblue_entity(driver, actblue) get_entity_for_disbursements(driver, actblue) elem = driver.find_element_by_id("SearchResults") if not elem: print("Entity doesn't exist: %s" % actblue) return clicked = False for ee in elem.find_elements_by_tag_name("td"): if ee.text == actblue: ee.parent.find_elements_by_tag_name( 'td')[0].find_element_by_tag_name('a').click() clicked = True break if not clicked: print("Couldn't find matching element for %s" % actblue) return time.sleep(1) # Sleep 1 second so the page loads with open(contributions, 'r') as f: reader = csv.DictReader(f) for row in reader: time.sleep(1) # Sleep 1 second so the page loads fee_date = datetime.strptime( row['Date'], '%Y-%m-%d %H:%M:%S') elem = driver.find_element_by_id('Date') elem.send_keys(fee_date.strftime("%m/%d/%Y")) fee_amount = Decimal(row['Fee']) elem = driver.find_element_by_id('Amount') elem.send_keys("{:.2f}".format(fee_amount)) elem = Select( driver.find_element_by_id('FppcSpendCodeDropDownField')) elem.select_by_value("OFC") elem = driver.find_element_by_id('DescriptionField') elem.send_keys('Service Fee') elem = driver.find_element_by_id('ElectionCycle-input') elem.send_keys('Primary') elem = driver.find_element_by_id('form-submit-button') elem.click()
def login(): go = driver.find_element_by_id("btnConfirm2") go.click() time.sleep(1) #schoolName scName = driver.find_element_by_class_name("searchBtn") scName.click() time.sleep(1) scName = Select(driver.find_element_by_id("sidolabel")) scName.select_by_visible_text(cp_name) scName = Select(driver.find_element_by_id("crseScCode")) scName.select_by_visible_text(sc_level) scName = driver.find_element_by_id("orgname") scName.send_keys(sc_name) scName = driver.find_element_by_class_name("searchBtn") scName.click() scName = driver.find_element_by_class_name("layerSchoolArea") scName.click() scName = driver.find_element_by_xpath("//*[text() = '" + sc_name + "']") scName.click() scName = driver.find_element_by_class_name("layerFullBtn") scName.click() time.sleep(1) #name/DoB id = driver.find_element_by_id("user_name_input") id.send_keys(u_name) id = driver.find_element_by_id("birthday_input") id.send_keys(u_dob) go = driver.find_element_by_id("btnConfirm") go.click() #pw time.sleep(1) pw = driver.find_element_by_class_name("input_text_common") pw.send_keys(u_pw) go = driver.find_element_by_id("btnConfirm") go.click()
def test_Add_students(self): user = "******" pwd = "PW" driver = self.driver driver.maximize_window() driver.get("https://om4k-1.herokuapp.com") elem = driver.find_element_by_link_text("Login").click() elem = driver.find_element_by_id("id_username") elem.send_keys("Sravani") elem = driver.find_element_by_id("id_password") elem.send_keys("srav12345") driver.find_element_by_xpath("//button[contains(.,'Submit')]").click() # Click Student List elem = driver.find_element_by_xpath( "//*[@id='wrapper']/nav/div[2]/ul/li[2]/a").click() #Click Add Student elem = driver.find_element_by_xpath( "//*[@id='page-wrapper']/div/div/div/a/span").click() # "Opened Page to Add Mentor" elem = driver.find_element_by_id("id_Student_id") elem.send_keys("s_10") elem = driver.find_element_by_id("id_Student_name") elem.send_keys("Samaira") elem = driver.find_element_by_id("id_Student_curr_grade") elem.send_keys("B") elem = driver.find_element_by_id("id_Student_prev_grade") elem.send_keys("C") elem = driver.find_element_by_id("id_Student_Class") elem.send_keys("9") elem = driver.find_element_by_id("id_Parents_email") email = "*****@*****.**" elem.send_keys(email) elem = driver.find_element_by_id("id_Parents_phone") elem.send_keys("4025143673") elem = driver.find_element_by_id("id_School") elem.send_keys("UNO Omaha") elem = Select(driver.find_element_by_id("id_Men_name")) elem.select_by_value("2") elem = Select(driver.find_element_by_id("id_Emp_name")) elem.select_by_value("1") elem = driver.find_element_by_id("id_Comments") elem.send_keys("Need to guide him about Future options") # time.sleep(2) elem = driver.find_element_by_xpath( "//*[@id='page-wrapper']/div/form/button").click() time.sleep(5)
def navigate_to_class(course_number, subject, browser): print('Navigating...') print('Searching for open sections of ' + subject + ' ' + course_number + '.') # Click on "Student Center" elem = browser.find_element_by_id('crefli_HC_SSS_STUDENT_CENTER') elem.click() # Wait to ensure the page has loaded time.sleep(5) # Switch to the iframe frame = browser.find_element_by_id('ptifrmtgtframe') browser.switch_to.frame(frame) # Click on Search elem = browser.find_element_by_id('DERIVED_SSS_SCR_SSS_LINK_ANCHOR1') elem.click() # Wait to ensure the page has loaded time.sleep(5) # Select the Institution elem = Select( browser.find_element_by_id('CLASS_SRCH_WRK2_INSTITUTION$31$')) elem.select_by_visible_text('Baruch College') # Wait to ensure the choice is populated time.sleep(5) # Select CIS elem = Select(browser.find_element_by_id('SSR_CLSRCH_WRK_SUBJECT_SRCH$0')) elem.select_by_visible_text(subject) # Input the course number elem = browser.find_element_by_id('SSR_CLSRCH_WRK_CATALOG_NBR$1') elem.send_keys(course_number) # Click Search elem = browser.find_element_by_id('CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH') elem.click() # Wait to ensure the page has loaded time.sleep(5)
def dropdownselector(self,idstr,selected): try: delay=2 select = Select(WebDriverWait(self.driver, delay).until(EC.element_to_be_clickable((By.ID, idstr)))) select.select_by_visible_text(selected) select.send_keys(Keys.TAB) select = Select(WebDriverWait(self.driver, delay).until(EC.element_to_be_clickable((By.ID, idstr)))) self.cf_save(1) return(True) except NoSuchElementException: self.cf_save(1) self.switch_tar() self.dropdownselector(idstr,selected) except ElementClickInterceptedException: self.cf_save(1) self.dropdownselector(idstr,selected) except: pass
def add_log_detailed(self, cnt): self.web.switch_to.frame("main") ele = Select(self.web.find_element_by_name('type')) ele.select_by_value(self.plan_num) ele = self.web.find_element_by_name('yy') ele.clear() ele.send_keys(self.set_yy) ele = self.web.find_element_by_name('mm') ele.clear() ele.send_keys(self.set_mm) ele = self.web.find_element_by_name('dd') ele.clear() ele.send_keys(self.set_dd[cnt]) ele = self.web.find_element_by_name('hrs') ele.clear() ele.send_keys(self.set_hrs[cnt]) ele = self.web.find_element_by_name('workin') ele.clear() ele.send_keys(self.set_workin) self.web.find_element_by_xpath('/html/body/form/center/input').click()
def login_into_horizon(self): """ first login into Horizon Dashboard """ logging.info("logging into {}".format(self.horizon_login_url)) try: self.driver.get(self.horizon_login_url) pageElement = Select(self.driver.find_element_by_name("auth_type")) if self.auth_type == 'Keystone': pageElement.select_by_value('credentials') #pageElement.select_by_visible_text('Keystone Credentials') pageElement = self.driver.find_element_by_name("username") pageElement.send_keys(self.username) pageElement = self.driver.find_element_by_name("password") pageElement.send_keys(self.password) pageElement = self.driver.find_element_by_css_selector( "button[type='submit']") pageElement.click() else: #pageElement.select_by_value('saml2') pageElement = self.driver.find_element_by_id("loginBtn") pageElement.click() element = WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.NAME, "username"))) #pageElement = self.driver.find_element_by_name("Connect") pageElement = self.driver.find_element_by_name("username") pageElement.send_keys(self.username) pageElement = self.driver.find_element_by_name("password") pageElement.send_keys(self.password) pageElement = self.driver.find_element_by_css_selector( "input[type='submit'][value='Login']") pageElement.click() except NoSuchElementException: raise exceptions.PageSourceException("Element not found") navigationStart = self.driver.execute_script( "return window.performance.timing.navigationStart") responseStart = self.driver.execute_script( "return window.performance.timing.responseStart") domComplete = self.driver.execute_script( "return window.performance.timing.domComplete") if "Invalid" in self.driver.page_source: raise exceptions.LoginFailureException('Invalid Username/Password') backendPerformance = responseStart - navigationStart frontendPerformance = domComplete - responseStart totalTime = (backendPerformance + frontendPerformance) logging.info("load time [Login Page] is {} ms".format(totalTime)) return {'Login Page': str(totalTime) + " ms"}
def test_blog(self): user = "******" pwd = "instructor1a" driver = self.driver driver.maximize_window() driver.get("http://127.0.0.1:8000/admin") elem = driver.find_element_by_id("id_username") elem.send_keys(user) elem = driver.find_element_by_id("id_password") elem.send_keys(pwd) elem.send_keys(Keys.RETURN) driver.get("http://127.0.0.1:8000/home") assert "Logged In" time.sleep(5) elem = driver.find_element_by_xpath( "html/body/div/div/div/div[2]/div/div/div/div/div[2]/div/div/p[2]/a" ).click() time.sleep(5) elem = driver.find_element_by_xpath( "html/body/div/div/div/div[3]/table/tbody/tr[3]/td[8]/a").click() time.sleep(5) elem = Select(driver.find_element_by_id('id_cust_name')) elem.select_by_visible_text('Lillian Wells') elem = driver.find_element_by_id("id_service_category") elem.clear() elem.send_keys("Brownies") elem = driver.find_element_by_id("id_description") elem.clear() elem.send_keys( "We need some brownies for children at an event we are hosting.") elem = driver.find_element_by_id("id_location") elem.clear() elem.send_keys("15th O Circle") elem = driver.find_element_by_id("id_service_charge") elem.clear() elem.send_keys("79.53") time.sleep(5) elem.send_keys(Keys.RETURN) assert "Posted Service Entry" driver.get("http://127.0.0.1:8000/service_list")
def test_blog(self): user = "******" pwd = "instructor1a" driver = self.driver driver.maximize_window() driver.get("http://127.0.0.1:8000/admin") elem = driver.find_element_by_id("id_username") elem.send_keys(user) elem = driver.find_element_by_id("id_password") elem.send_keys(pwd) elem.send_keys(Keys.RETURN) driver.get("http://127.0.0.1:8000/home") assert "Logged In" time.sleep(5) elem = driver.find_element_by_xpath( "html/body/div/div/div/div[2]/div/div/div/div/div[3]/div/div/p[2]/a" ).click() time.sleep(5) elem = driver.find_element_by_xpath( "html/body/div/div/div/div[3]/table/tbody/tr[3]/td[7]/a").click() time.sleep(5) elem = Select(driver.find_element_by_id('id_cust_name')) elem.select_by_visible_text('Lillian Wells') elem = driver.find_element_by_id("id_product") elem.clear() elem.send_keys("Cupcakes") elem = driver.find_element_by_id("id_p_description") elem.clear() elem.send_keys("Red Velvet") elem = driver.find_element_by_id("id_quantity") elem.clear() elem.send_keys("60") elem = driver.find_element_by_id("id_charge") elem.clear() elem.send_keys("42.58") time.sleep(5) elem.send_keys(Keys.RETURN) assert "Posted Product Entry" driver.get("http://127.0.0.1:8000/product_list")
def test_Admin_election_creation(self): driver = self.driver driver.get("http://*****:*****@gmail.com" + Keys.TAB + "qwerty1234" + Keys.TAB + Keys.ENTER) user = driver.find_element_by_id("createelection") user.send_keys(Keys.ENTER) # user = driver.find_element_by_name("electionType") # user.is_selected("PresedentialElection") user = Select(driver.find_element_by_name('electionType')) #user.select_by_visible_text("PresidentialElection") user.select_by_value("PresidentialElection") user = Select(driver.find_element_by_name('state')) user.select_by_value("IA") user = driver.find_element_by_name("electionID") user.send_keys("987346") user = driver.find_element_by_name("startDate") user.send_keys("02/04/2018") user = driver.find_element_by_name("endDate") user.send_keys("01/05/2018") user.send_keys(Keys.TAB) user.send_keys(Keys.TAB) user.send_keys(Keys.ENTER) assert "Upload" in driver.page_source
def fill_in_field(self, field): if field._type == 'checkbox': input_fields = self.browser.find_elements_by_xpath( "//input[@name='%s']" % field.name) for input_field in input_fields: input_value = input_field.get_attribute('value') is_selected = not input_field.is_selected() same_content = input_value in \ [str(value) for value in field.content] if same_content and is_selected: input_field.click() elif field._type == 'autocomplete': # autocomplete add a kind of new input field with -autocomplete # at the end of the field name. # So we first search this input. Then we send him some value fieldname = field.name + '-autocomplete' input_field = self.browser.find_element_by_name(fieldname) input_field.clear() input_field.send_keys(field.content) # After a while, we select the first value displayed self.browser.implicitly_wait(2) select_element = '.yourlabs-autocomplete[data-input-id="id_' + \ fieldname + '"] [data-value]' choices = self.browser.find_elements_by_css_selector( select_element) choices[0].click() elif field._type == Select: input_field = self.browser.find_element_by_name(field.name) input_field = Select(input_field) input_field.select_by_visible_text(field.content) else: input_field = self.browser.find_element_by_name(field.name) # Delete content first if field._type != 'file': input_field.clear() input_field.send_keys(field.content)
class elemen: def __init__(self,id): try: self.elem = driver.find_element_by_id(id) except Exception as e: self.elem = driver.find_element_by_link_text(id) def sel(self,opt): self.elem = Select(self.elem) self.elem.select_by_visible_text(opt) def click(self): self.elem.click() def change(self,val): self.elem.send_keys(Keys.CONTROL + "a") self.elem.send_keys(Keys.DELETE) self.elem.send_keys(val) self.elem.send_keys(Keys.RETURN) def printelem(self): print(self.elem)
def chakanxinzeng(self): #查勘新增6(ok) self.driver = webdriver.Ie() self.driver.maximize_window() self.driver.get(url) self.driver.find_element_by_id("username").send_keys(lpun) self.driver.find_element_by_id("password").send_keys(pw) self.driver.find_element_by_id("bt_submit").submit() time.sleep(3) self.driver.switch_to_frame("leftFrame") self.driver.find_element_by_link_text("理赔子系统").click() self.driver.find_element_by_link_text("查勘管理").click() self.driver.find_element_by_link_text("查勘新增").click() self.driver.switch_to_default_content() self.driver.implicitly_wait(5) self.driver.switch_to_frame("mainFrame") #报案号码 self.driver.find_element_by_name('GcSurveyMainDtoRegistNo').send_keys( self.baoanhao) #查询 self.driver.find_element_by_xpath( '//*[@id="BeforeOverViewResult"]/tbody/tr[2]/td/input').click() self.driver.switch_to_frame("QueryResultFrame") #报案号码 self.driver.find_element_by_xpath( '//*[@id="ResultTable"]/tbody/tr/td[2]/a').click() time.sleep(4) self.driver.switch_to_alert().accept() self.driver.switch_to_default_content() self.driver.implicitly_wait(5) self.driver.switch_to_frame("mainFrame") time.sleep(3) #人伤信息 self.driver.find_element_by_css_selector( 'td[title="personInfomation"]').click() #+ self.driver.find_element_by_xpath( '//*[@id="person"]/tfoot/tr[1]/td/p/input').click() time.sleep(3) #点击详细信息 self.driver.find_elements_by_css_selector( 'input[value="详细信息"]')[1].click() time.sleep(2) self.driver.switch_to_frame("detailFrame") #姓名 self.driver.find_element_by_name( 'GcSurveyPersonDtoPersonCName').send_keys(tbname) # xingming = self.driver.find_element_by_xpath('//*[@id="personInfo"]/tbody/tr[1]/td[4]/input[2]') # ActionChains(self.driver).double_click(xingming).perform() # self.driver.find_element_by_xpath('//*[@id="personInfo"]/tbody/tr[1]/td[4]/input[2]').send_keys(Keys.ENTER) # self.driver.find_element_by_xpath('//*[@id="personInfo"]/tbody/tr[1]/td[4]/input[2]').send_keys(Keys.ENTER) time.sleep(2) #职业大类 self.driver.find_element_by_xpath( '//*[@id="personInfo"]/tbody/tr[6]/td[2]/input[1]').send_keys( "00101") self.driver.find_element_by_xpath( '//*[@id="personInfo"]/tbody/tr[6]/td[2]/input[1]').send_keys( Keys.TAB) time.sleep(2) #性别 __xb = Select( self.driver.find_element_by_xpath( "//*[@id='personInfo']/tbody/tr[2]/td[2]/select")) __xb.select_by_value("1") # __xb.select_by_index(1) #意外伤害 self.driver.find_element_by_link_text("意外伤害").click() self.driver.find_element_by_css_selector( 'input[value="IC017"]').click() #保存 self.driver.find_element_by_xpath( '/html/body/form/table[8]/tbody/tr/td[1]/input').click() #基本信息 time.sleep(3) self.driver.switch_to_default_content() self.driver.switch_to_frame('mainFrame') self.driver.find_element_by_css_selector("td[title='main']").click() time.sleep(3) #财产查勘 #点+号 self.driver.find_element_by_xpath( '//*[@id="propFee"]/tfoot/tr/td/p/input').click() self.driver.implicitly_wait(5) #险别 # __xb = self.driver.find_elements_by_name('GcSurveyPropDtoKindCode')[1] # ActionChains(self.driver).double_click(__xb).perform() # __xb.send_keys(Keys.ENTER) # __xb.send_keys(Keys.ENTER) # xb = 'var q = document.getElementsByName("GcSurveyPropDtoKindCode");q[1].value ="%s";'% "1128001"#1109016 # self.driver.execute_script(xb) self.driver.find_elements_by_name( 'GcSurveyPropDtoKindCode')[1].send_keys("1109016") self.driver.find_elements_by_name( 'GcSurveyPropDtoKindCode')[1].send_keys(Keys.TAB) #险别估损金额 self.driver.find_elements_by_name( 'GcSurveyPropDtoSumLoss')[1].send_keys("200") #人伤查勘估损 self.driver.find_element_by_xpath( '//*[@id="injured"]/tfoot/tr/td/p/input').click() time.sleep(2) #姓名 __xm = self.driver.find_elements_by_name( 'GcSurveyPersonFeeDtoPersonCName')[1] ActionChains(self.driver).double_click(__xm).perform() __xb.send_keys(Keys.ENTER) __xb.send_keys(Keys.ENTER) #险别 __xb1 = self.driver.find_elements_by_name( 'GcSurveyPersonFeeDtoKindCode')[1] ActionChains(self.driver).double_click(__xb1).perform() __xb1.send_keys(Keys.ENTER) __xb1.send_keys(Keys.ENTER) #险别估损金额 self.driver.find_elements_by_name( 'GcSurveyPersonFeeDtoSumLoss')[1].send_keys("200") #查勘报告 self.driver.find_element_by_id('img2').click() #出现经过 self.driver.find_element_by_name('GcSurveyMainDtoDamageDescription' ).send_keys("Me Against the World") #查勘新增 self.driver.find_element_by_name('GcSurveyMainDtoContext').send_keys( "让世界感受痛楚") #报损及损失核定 self.driver.find_element_by_name('GcSurveyMainDtoExt1').send_keys( "没人知道我的痛苦有多深") #处理意见 self.driver.find_element_by_id('img1').click() self.driver.find_element_by_name('GcSurveyMainDtoExt6').send_keys("同意") #点提交 self.driver.find_element_by_xpath( '//*[@id="button"]/tbody/tr/td/input[4]').click() self.driver.switch_to_alert().accept() #取文本 time.sleep(5) self.driver.switch_to_default_content() self.driver.switch_to_frame("mainFrame") succ = self.driver.find_element_by_xpath( '/html/body/form/table/tbody/tr/td/table[1]/tbody/tr[2]/td').text __retext = succ[0:4] print(__retext) self.driver.quit() return __retext
def impl(context): dropdown = Select(find_id_with_wait(context, "group-select")) dropdown.select_by_visible_text("0") # For some reason this only triggers properly if you defocus or press enter after the select dropdown = find_id_with_wait(context, "group-select") dropdown.send_keys(Keys.RETURN)
blank = Select(driver.find_element_by_css_selector('#mzm')) blank.select_by_visible_text('汉族') # 替换成自己的民族 blank = driver.find_element_by_css_selector( 'label[for=xbm_1]') # 替换成自己的性别 男生xbm_0 女生xbm_1 blank.click() blank = driver.find_element_by_css_selector( 'label[for=hfm_0]') # 替换成自己的婚姻状态 未婚hfm_0 已婚hfm_1 依次增加 blank.click() blank = Select(driver.find_element_by_css_selector('#zzmmm')) blank.select_by_visible_text('中国共产主义青年团团员') # 替换成自己的政治面貌 blank = driver.find_element_by_css_selector('#txdz') blank.send_keys('北京市朝阳区定福庄东街一号中国传媒大学') # 替换成自己的通信地址 blank = driver.find_element_by_css_selector('#yzbm') blank.send_keys('100024') # 替换成自己的邮编 blank = driver.find_element_by_css_selector('#lxdh') blank.send_keys('0') # 替换成自己的固定电话 blank = driver.find_element_by_css_selector('#dzxx') blank.send_keys('@qq.com') # 替换成自己的邮箱 blank = Select(driver.find_element_by_css_selector('#kslym')) blank.select_by_visible_text('普通全日制应届本科毕业生') # 替换成自己的身份 blank = Select(driver.find_element_by_css_selector('#xxxs')) blank.select_by_visible_text('普通全日制') # 替换成自己的培养方式
select_doctype = Select(driver.find_element_by_id("DocumentTypeID")) select_doctype_list=[option.text for option in select_doctype.options] select_status = Select(driver.find_element_by_id("DocumentStatusesID")) select_version = driver.find_element_by_id("OfficialVersion") select_mtg.send_keys(d['mtg_name']) if d['mtg_name']!='select': if d['mtg_button_type']=='Post-Meeting': select_postmeeting_button.click() else: select_meeting_button.click() select_access.select_by_visible_text(d["access"]) if d['DOC_TYPE'] in select_doctype_list: select_doctype.select_by_visible_text(d["DOC_TYPE"]) else: select_doctype.send_keys(d["DOC_TYPE"]) select_status.select_by_visible_text("Final") select_version.send_keys(d["version"]) next_button=WebDriverWait(driver,10).until( EC.presence_of_element_located((By.CSS_SELECTOR,".blue-button.nxtButton.col-md-12")) ) next_button.click() upload_button = WebDriverWait(driver,10).until( EC.element_to_be_clickable((By.XPATH, "//*[@id='sample']")) ) driver.execute_script("arguments[0].scrollIntoView(true);", upload_button) upload_button.click() time.sleep(1) upload_ok = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.ID, "DocumentUploadOK")) )
for (key,value) in shipping_info_next: ele_selector = key ele = Select(driver.find_element(By.ID,ele_selector)) ele.select_by_visible_text(value) # shipping_info_next = { 'address_zip' : '80302', } time.sleep(SLEEP_SECS) for key,value in shipping_info_next.iteritems(): ele_selector = key ele = driver.find_element_by_id(ele_selector) ele.send_keys(value) # shipping_info_next = { 'speed' : 'speed-std', } time.sleep(SLEEP_SECS) for key,value in shipping_info_next.iteritems(): ele_selector = key ele = driver.find_element_by_id(value) ele.click() #click add to cart time.sleep(SLEEP_SECS) ele_number = 0
def consulta_webs(fichero, ficheros_respaldo, municipio, provincia): #obtiene datos de ine cod_municipio = procesos_comunes.valor_elemento_xml( fichero, './/Estacion_Certificada/Datos_Emplazamiento/Cod_INE_Termino_Municipal' ) cod_provincia = procesos_comunes.valor_elemento_xml( fichero, './/Estacion_Certificada/Datos_Emplazamiento/Cod_INE_Provincia') ine = procesos_comunes.obtiene_datos_ine(fichero, cod_municipio['Valor'], cod_provincia['Valor'], ficheros_respaldo) #print(ine) #obtienes datos de calle tipo_via = procesos_comunes.valor_elemento_xml( fichero, './/Estacion_Certificada/Datos_Emplazamiento/Calle/Tipo_Via')['Valor'] nombre_via = procesos_comunes.valor_elemento_xml( fichero, './/Estacion_Certificada/Datos_Emplazamiento/Calle/Nombre_Via' )['Valor'] numero_portal = procesos_comunes.valor_elemento_xml( fichero, './/Estacion_Certificada/Datos_Emplazamiento/Calle/Numero_Portal' )['Valor'] #obtiene referencia catastral dato_Referencia_Catastral = procesos_comunes.valor_elemento_xml( fichero, './/Estacion_Certificada/Datos_Emplazamiento/Referencia_Catastral' )['Valor'] #Se abre firefox driver = webdriver.Firefox( executable_path=os.path.join(ficheros_respaldo, 'geckodriver.exe')) #driver = webdriver.Firefox() wcatastro = 'https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCConCiud.aspx?UrbRus=U&RefC=' \ + dato_Referencia_Catastral + '&esBice=&RCBice1=&RCBice2=&DenoBice=&from=OVCBusqueda&pest=rc&RCCompleta=' \ + dato_Referencia_Catastral + "&final=&del=" + ine['Cod_Provincia_Catastro'] \ + "&mun=" + ine['Cod_Municipio_Catastro'] print(wcatastro) #ing.debug('Apertura de web catastro') try: driver.get(wcatastro) # leemos datos devueltos por catastro select = driver.find_element_by_xpath( "/html/body/form/fieldset/div[2]/div[2]/div[2]/div/div[1]/div[2]/div/div[2]/div/span/label" ) # obtenemos los datos Datos_Direccion_Catastro = select.text print(" referencia catastral ok") # comprobamos si son correctos los datos de catastro contra los de xml except Exception as e: # codigo catastro erroneo, crear reparo #print("ERROR codigo catastro ") #logging.debug("ERROR codigo catastro ") pass #Abre Infoantenas # Opens a new tab driver.execute_script("window.open()") # Switch to the newly opened tab driver.switch_to.window(driver.window_handles[1]) # Navigate to new URL in new tab driver.get("https://geoportal.minetur.gob.es/VCTEL/vcne.do") # sacamos provincia try: select = Select(driver.find_element_by_id('lstProvincias')) select.select_by_visible_text(provincia) # BUSCAMOS MUNICIPIO select = Select(driver.find_element_by_id('listmuni')) select.select_by_visible_text(municipio) print("OK municipio coincide con combo infoantenas") #logging.debug("OK municipio coincide con combo infoantenas") except: #print("ERROR datos de municipio no coincide con combo infoantenas: ") #logging.debug("ERROR datos de municipio no coincide con combo infoantenas: ") pass try: # BUSCAMOS CALLE print("nombre de calle ", nombre_via) #logging.debug("nombre de calle ", nombre_via) select = driver.find_element_by_xpath('//*[@id="nom_calle"]') select.send_keys(nombre_via) print("Busqueda de la calle OK ") #logging.debug("Busqueda de la calle OK ") except Exception as e: #print("ERROR al realizar la busqueda de la calle: ") #logging.debug("ERROR al realizar la busqueda de la calle: ") pass try: driver.find_element_by_xpath( '/html/body/table/tbody/tr[2]/td[2]/div/form/table/tbody/tr[3]/td/div[1]/table/tbody/tr[11]/td/input[1]' ).click() #select.send_keys(Keys.RETURN) except Exception as e: #print("ERROR al realizar la busqueda: ") #logging.debug("ERROR al realizar la busqueda: ") pass try: # METEMS ZOOM A MAPA time.sleep(2) driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() # leer texto OpenLayers.Control.MousePosition_18 select = driver.find_element_by_id( 'OpenLayers.Control.MousePosition_18') Coordenadas = select.text # limpiamos y convertimos en array Coordenadas = Coordenadas.replace('ETRS89:', '') Coordenadas = Coordenadas.replace(' ', '') Coordenadas = Coordenadas.replace('N', '') Coordenadas = Coordenadas.replace('O', '') # con array coordenadoas crear funcion que reste coordenadas web y xml y segun resultado click en flecha de forma recursiva # xpath mapa: //*[@id="OpenLayers.Layer.Vector.RootContainer_33_svgRoot"] except Exception as e: #print("error problemas al manipular el mapa: ") #logging.debug("error problemas al manipular el mapa: ") pass # Abre Fomento # Esta comentado por que habre ventana pero se queda pensando el programa , no termina. # falta cerrar ventana emergente y meter datos # Opens a new tab driver.execute_script("window.open()") # Switch to the newly opened tab driver.switch_to.window(driver.window_handles[2]) # Navigate to new URL in new tab driver.get("https://mapas.fomento.gob.es/VisorSIU/") time.sleep(2) try: select = driver.find_element_by_xpath( '/html/body/div[2]/div[1]/div[3]/div[2]/div[2]/div[2]/button' ).click() select = driver.find_element_by_xpath( '//*[@id="esri_dijit_Search_0_input"]') select.send_keys(tipo_via + " " + nombre_via + " " + str(numero_portal) + ", " + ine['Nombre_Municipio_Catastro'] + ", " + ine['Nombre_Provincia']) select.submit() print("OK busqueda de calle") #logging.debug("OK busqueda de calle") # no se puede obtener el tipo de suelo que es por que hay que pulsar en el punto except Exception as e: #print("ERROR al hacer la busqueda en web de fomento: ") #logging.debug("ERROR al hacer la busqueda en web de fomento: ") pass # Abre Iberpix # Run other commands in the new tab here # Opens a new tab driver.execute_script("window.open()") # Switch to the newly opened tab driver.switch_to.window(driver.window_handles[3]) # Navigate to new URL in new tab driver.get("https://www.ign.es/iberpix2/visor/") # Run other commands in the new tab here time.sleep(10) try: select = driver.find_element_by_xpath( "/html/body/ign-map/div/menu-routecal/div/div[1]/div/input") select.send_keys(tipo_via + " " + nombre_via + " " + str(numero_portal) + ", " + ine['Nombre_Municipio_Catastro'] + ", " + ine['Nombre_Provincia']) time.sleep(4) # falta arreglar que pulse en la primera opcion # select.sendKeys(Keys.DOWN).sendKeys(Keys.ENTER) print("busqueda de calle ok") #logging.debug("busqueda de calle ok") except Exception as e: #print("Error al hacer la busqueda en iberpix: ") #logging.debug("Error al hacer la busqueda en iberpix: ") pass """
def test_edit_view_project(self): # Given cls = self.__class__ root = cls.root browser = cls.browser ui = cls.ui data_path = os.path.join(root, 'test') self.wait = WebDriverWait(browser, 20) # When # Create a new project. self._get('new-project').click() # Set the name. e = self._get('edit-name') e.clear() e.send_keys('test1') # Set the path. self._get('edit-path').send_keys(data_path) # Setup the tags. self._get('remove-tag-0').click() e = self._get('new-tag') e.send_keys('comments, count, processed') self._get('add-tag').click() e = self._get('tag-type-1') e = Select(e) e.select_by_visible_text('int') e = Select(browser.find_element_by_id('tag-type-2')) e.select_by_visible_text('bool') self._get('new-extension').send_keys('.txt') self._get('add-extension').click() self._wait_while(lambda: len(ui.editor.extensions) == 0) # Save changes. self._get('apply').click() p = ui.vixen.projects[0] self._wait_while(lambda: len(p.last_save_time) == 0) # Then self.assertEqual(len(ui.vixen.projects), 1) self.assertEqual(p.name, 'test1') self.assertEqual(p.root.path, data_path) self.assertEqual(p.tags[0].name, 'comments') self.assertEqual(p.tags[1].name, 'count') self.assertEqual(p.tags[2].name, 'processed') self.assertEqual(p.tags[1].type, 'int') self.assertEqual(p.tags[2].type, 'bool') self.assertEqual(p.number_of_files, 4) m = p.get('root.txt') self.assertEqual(m.relpath, 'root.txt') self.assertEqual(m.type, 'text') self.assertEqual(len(m.tags), 3) # Test control-s last_save = p.last_save_time e = self._get('edit-name') e.clear() e.send_keys('Project 1') e = browser.find_element_by_id('apply') e.send_keys(Keys.CONTROL, "s") self._wait_while(lambda: p.last_save_time == last_save) # Then self.assertEqual(p.name, 'Project 1') # When # Now view the project. self._get('view-0').click() # Navigate down a directory. e = self._get('path-0').click() viewer = ui.viewer self._wait_while(lambda: viewer.current_dir.name == 'test') self.assertTrue('sub' in viewer.current_dir.name) self.assertEqual(ui.mode, 'view') e = self._get('go-to-parent') e.send_keys('') time.sleep(0.2) e.click() browser.find_element_by_id('go-to-parent').click() self._wait_while(lambda: viewer.current_dir.name == 'sub') self.assertEqual(viewer.current_dir.name, 'test') e = self._get('path-2') e.click() self._wait_while(lambda: viewer.current_file is None) self.assertEqual(viewer.current_file.name, 'root.txt') # Change some tag information and save. last_save = p.last_save_time e = self._get('tag-0') e.send_keys('') e.send_keys('test') self._get('tag-1').clear() self._get('tag-1').clear() self._get('tag-1').send_keys('1') self._get('save').send_keys('') self._get('save').click() if cls.driver == 'firefox': self._get('save').click() self._wait_while(lambda: p.last_save_time == last_save) # Then m = p.get('root.txt') self._wait_while(lambda: m.tags['count'] == 0) self.assertEqual(m.tags['comments'], 'test') self.assertEqual(m.tags['count'], 1) # Change some tag information and save using ctrl+s last_save = p.last_save_time self._get('tag-0').send_keys('2') self._get('tag-1').clear() self._get('tag-1').send_keys('12') self._get('tag-1').clear() self._get('tag-1').send_keys('12') self._get('go-to-parent').send_keys(Keys.CONTROL, "s") self._wait_while(lambda: p.last_save_time == last_save) self.assertEqual(m.tags['comments'], 'test2') self.assertEqual(m.tags['count'], 12) # Now check if search works. self._get('search-text').send_keys('count:12') self._get('search').click() self._wait_while(lambda: not ui.viewer.search_completed) # Then e = self._get('search-item-0') e.click() self._wait_while(lambda: viewer.media is None) self.assertTrue(viewer.media.file_name, 'root.txt') self.assertEqual(ui.viewer.is_searching, True) self.assertEqual(ui.viewer.search_completed, True) self._get('clear-search').click() self._wait_while(lambda: ui.viewer.search_completed) e = self._get('path-2') self.assertEqual(ui.viewer.is_searching, False) # When # Now edit the project. browser.find_element_by_link_text('Home').click() e = self._get('edit-0') e.click() self._wait_while(lambda: ui.editor.project is None) # Then self.assertEqual(ui.mode, 'edit') self.assertEqual(ui.editor.project, ui.vixen.projects[-1]) # When # Finally remove the projects. done = False count = 0 while not done and count < 3: try: e = self._get('remove-0') e.send_keys('') e.click() confirm = browser.switch_to_alert() confirm.accept() done = True except NoAlertPresentException: count += 1 time.sleep(0.1) self._wait_while(lambda: len(ui.vixen.projects) > 0) self.assertEqual(len(ui.vixen.projects), 0)
# 학교 검색 ele = driver.find_element_by_id('schul_name_input') ele.click() time.sleep(2) # 시/도 선택 :: 'Select'를 활용한 드롭다운 메뉴 선택 ele = Select(driver.find_element_by_id("sidolabel")) ele.select_by_index(8) # 학교명 검색 :: 'Select'를 활용한 드롭다운 메뉴 선택 ele = Select(driver.find_element_by_id("crseScCode")) ele.select_by_index(2) # 학교명 입력 ele = driver.find_element_by_id('orgname') ele.send_keys(student["school"]) ele = driver.find_element_by_class_name("searchBtn") ele.click() time.sleep(1) # 학교명 선택(처음에는 나타나지 않음) ele = driver.find_element_by_tag_name("em") ele.click() time.sleep(1) # 학교선택 정보 최종 제출 ele = driver.find_element_by_class_name("layerFullBtn") ele.click() time.sleep(2)
# @Author :python13_marimo # @Email :[email protected] # @File :study_element.py # @Sofeware :PyCharm Community Edition from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Chrome() driver.get('http://www.baidu.com') wait = WebDriverWait(driver, 15, 1) #对象名,总时长,轮询周期 wait.until(EC.element_to_be_clickable("id", "kw")) wait.until(EC.element_to_be_clickable(By.ID, "kw")) #until(判断条件) #EC.方法名(定位方式,定位表达式) el = driver.find_elements_by_xpath( '//*[@id="adv-setting-5"]/select/option[text()="微软 Excel (.xls)"]') w = Select(el) print(w.options) w = driver.find_element_by_id("kw") w.send_keys('asd', Keys.DOWN) action = ActionChains(driver) el = driver.find_elements_by_xpath( '//*[@id="adv-setting-5"]/select/option[text()="微软 Excel (.xls)"]') wl = action.move_to_element_with_offset(el).click().double_click() wl.perform()
def test_mobile_form_can_be_submitted_and_redirect(self): with self.settings(DEBUG=True): self.login() self.browser.get(self.live_server_url + '/assets/add') time.sleep(1) asset_type_field = Select(self.browser.find_element_by_id('id_select_asset_type')) asset_type_field.select_by_visible_text('Mobile') asset_tag_field = self.browser.find_element_by_id('id_add_asset_tag') asset_tag_field.send_keys('HD1269') asset_type_field = self.browser.find_element_by_id('id_add_imei') asset_type_field.send_keys('5') asset_type_field = self.browser.find_element_by_id('id_add_asset_status') asset_type_field.send_keys('Ready') asset_type_field = self.browser.find_element_by_id('id_add_asset_model') asset_type_field.send_keys('iPhone6') asset_type_field = self.browser.find_element_by_id('id_add_asset_condition') asset_type_field.send_keys('Good') asset_type_field = self.browser.find_element_by_id('id_add_storage') asset_type_field.send_keys('64GB') asset_type_field = self.browser.find_element_by_id('id_add_colour') asset_type_field.send_keys('White') asset_submit_button = self.browser.find_element_by_id('id_add_asset_submit') asset_submit_button.send_keys(Keys.RETURN) time.sleep(1) self.browser.get(self.live_server_url + '/assets') time.sleep(1) body = self.browser.find_element_by_tag_name('body') self.assertIn('HD1269', body.text)
def test_run(self): driver = self.driver driver.implicitly_wait(10) #url = 'https://login.salesforce.com/' url = 'https://na112.lightning.force.com/lightning/page/home' url_base = 'https://na112.lightning.force.com' driver.get(url) driver.maximize_window() username = '******' password = '******' # username = os.environ.get('sfdc_username') login_obj = {'username': '', 'password': '', 'login': ''} elem1 = driver.find_element_by_xpath("//input[@id='username']") elem2 = driver.find_element_by_xpath("//input[@id='password']") elem3 = driver.find_element_by_xpath("//input[@id='Login']") xpath = "//input[@id='username']" login_obj['username'] = elem1 login_obj['password'] = elem2 login_obj['login'] = elem3 login_obj.get('username').send_keys(username) login_obj.get('password').send_keys(password) login_obj.get('login').click() time.sleep(5) # Classic Home Page url = "https://na112.salesforce.com/home/home.jsp" driver.get(url) driver.save_screenshot(r'C:\temp\sfdc\login.png') #Accounts # ===================================================================== driver.get("https://na112.salesforce.com/001/o") time.sleep(5) locator = "new" elem = driver.find_element_by_name(locator) elem.click() # Opportunity Name locator = "opp3" text = f"QA Daily Check- {today()}" elem = driver.find_element_by_id(locator) elem.send_keys(text) # Account Name locator = "opp4" text = "LTE" elem = driver.find_element_by_id(locator) elem.send_keys(text) # Close Date locator = "opp9" text = "09/30/2019" elem = driver.find_element_by_id(locator) elem.send_keys(text) # Stage locator = "opp11" text = "Qualification" elem = Select(driver.find_element_by_id(locator)) elem.select_by_visible_text(text) # Save Button locator = "save" elem = driver.find_element_by_name(locator) elem.click() driver.save_screenshot(r'C:\temp\sfdc\account.png') # elem = driver.find_element_by_link_text('LTE-Product Rule') # elem.click() # elem = driver.find_element_by_partial_link_text('Quotes') # elem.click() # Related Links # ===================================================================== # Opportuity --> Contact Roles # locator = "html/body/div[5]/div[1]/section/div/div/div[1]/div[2]/div[1]/div/div[1]/div/header/div[2]/div/div[2]/ul/li[3]/a/div" # elem = driver.find_element_by_xpath(locator) # elem.click() # Opportuity --> Quote # locator = "html/body/div[5]/div[1]/section/div/div/div[1]/div[2]/div[1]/div/div[1]/div/header/div[2]/div/div[2]/ul/li[3]/a/div" # elem = driver.find_element_by_xpath(locator) # elem.click() # # Opportuity --> Product # locator = "html/body/div[5]/div[1]/section/div/div/div[1]/div[2]/div[1]/div/div[1]/div/header/div[2]/div/div[2]/ul/li[4]/a/div" # elem = driver.find_element_by_xpath(locator) # elem.click() # # Opportuity --> Quote Documents # locator = "html/body/div[5]/div[1]/section/div/div/div[1]/div[2]/div[1]/div/div[1]/div/header/div[2]/div/div[2]/ul/li[4]/a/div" # elem = driver.find_element_by_xpath(locator) # elem.click() # # Opportuity --> Contract # locator = "html/body/div[5]/div[1]/section/div/div/div[1]/div[2]/div[1]/div/div[1]/div/header/div[2]/div/div[2]/ul/li[4]/a/div" # elem = driver.find_element_by_xpath(locator) # elem.click() # # Opportuity --> Renewal Contract # locator = "html/body/div[5]/div[1]/section/div/div/div[1]/div[2]/div[1]/div/div[1]/div/header/div[2]/div/div[2]/ul/li[4]/a/div" # elem = driver.find_element_by_xpath(locator) # elem.click() # # Opportuity --> Note & Attachments # locator = "html/body/div[5]/div[1]/section/div/div/div[1]/div[2]/div[1]/div/div[1]/div/header/div[2]/div/div[2]/ul/li[4]/a/div" # elem = driver.find_element_by_xpath(locator) # elem.click() # Buttons # ===================================================================== # Opportunity --> Edit time.sleep(5) locator = "edit" elem = driver.find_element_by_name(locator) elem.click() locator = "opp14" text = "The oppty is created by script" elem = driver.find_element_by_id(locator) elem.send_keys(text) locator = "save" elem = driver.find_element_by_name(locator) elem.click() # locator = "save_new" # elem = driver.find_element_by_name(locator) # elem.click() # locator = "cancel" # elem = driver.find_element_by_name(locator) # elem.click() # # # # Delete # Include Document # Create Order time.sleep(3)
def create_nike(n, location, PROXY=False): n = n - 1 r_mail = ''.join( random.choice(string.ascii_letters + string.digits) for i in range(8)) + '@gmail.com' r_fn = ''.join(random.choice(string.ascii_letters) for i in range(4)) r_pas = ''.join( random.choice(string.digits + string.ascii_lowercase + string.ascii_uppercase + string.digits) for i in range(12)) r_ln = ''.join(random.choice(string.ascii_letters) for i in range(4)) if PROXY == True: chrome_options.add_argument('--proxy-server=http://%s' % proxiess[n]) print("Connected to proxy -> {}".format(proxiess[n])) else: print("Using without proxy.") driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chromedriver_location) if PROXY == True: print("Connected to proxy -> {}".format(proxiess[n])) print("Starting new session...") if location == 'CN2': os.system("cls") username = input("Input username for smscin... ") os.system("cls") token = input("Input token for smscin... ") os.system("cls") pid = input("Input pid for smscin... ") driver.get('https://www.nike.com/cn/zh_cn/s/register') try: time.sleep(4) try: flag = driver.find_element_by_xpath( "//div[@class='modal-close-glyph nsg-glyph--x']") flag.click() except: print("Something went wrong:/") input_num = driver.find_element_by_xpath("//input[@type='tel']") input_num.click() input_num.clear() input.send_keys(VerSMS.getmobile_cn(token, username, pid)) print("Number -> {}".format( VeySMS.getmobile_cn(token, username, pid))) time.sleep(2) send_code = driver.find_element_by_xpath( "//input[@value='Send Code']") send_code.click() time.sleep(15) code = driver.find_element_by_xpath("//input[@value='number']") code.click() code.clear() code.send_keys(VerSMS.getsms_cn(token, username, pid)) print("Code -> {}".format(VerSMS.getsms_cn(token, username, pid))) time.sleep(1) except Exception as e: print(e) else: try: if location == 'US': driver.get('https://www.nike.com/us/en_us/s/register') if location == 'UK': driver.get('https://www.nike.com/gb/en_gb/s/register') except Exception as e: print(e) time.sleep(5) '''if driver.find_element_by_class_name('exp-geodetect-notifier__title nsg-font-family--platform').is_displayed(): flag = driver.find_element_by_class_name('exp-geodetect-notifier__flag') flag.click()''' try: flag = driver.find_element_by_xpath( "//div[@class='modal-close-glyph nsg-glyph--x']") flag.click() except: print("Something went wrong:/") time.sleep(4) try: try: em = driver.find_element_by_name('emailAddress') em.click() except: print("Couldn't click!") time.sleep(1) em.clear() em.send_keys(r_mail) time.sleep(2) try: pas = driver.find_element_by_name('password') pas.click() except: print("Couldn't click!") time.sleep(1) pas.clear() try: pas.send_keys(r_pas) except: print("Couldn't send keys!") time.sleep(2) try: fn = driver.find_element_by_name('firstName') fn.click() except: print("Couldn't click!") time.sleep(1) fn.clear() try: fn.send_keys(r_fn) except: print("Couldn't send keys!") time.sleep(2) try: ln = driver.find_element_by_name('lastName') ln.click() except: print("Couldn't click!") time.sleep(1) ln.clear() try: ln.send_keys(r_ln) except: print("Couldn't send keys!") time.sleep(2) try: date_mm = Select( driver.find_element_by_id('nike-unite-date-id-mm')) for index in range(len(date_mm.options)): date_mm = Select( driver.find_element_by_id('nike-unite-date-id-mm')) date_mm.select_by_index(index) time.sleep(2) date_dd = Select( driver.find_element_by_id('nike-unite-date-id-dd')) for index in range(len(date_dd.options)): date_dd = Select( driver.find_element_by_id('nike-unite-date-id-dd')) date_dd.select_by_index(index) time.sleep(2) date_yyyy = Select( driver.find_element_by_id('nike-unite-date-id-yyyy')) for index in range(len(date_yyyy.options)): date_yyyy = Select( driver.find_element_by_id('nike-unite-date-id-yyyy')) date_yyyy.select_by_index(index) time.sleep(2) except: date_mm = driver.find_element_by_name('dateOfBirth') date_mm.clear() date_mm.send_keys('01.01.2000') try: genre = driver.find_element_by_xpath( "//span[contains(text(), 'Male')]") genre.click() except: print("Couldn't click!") time.sleep(2) try: login_btn = driver.find_element_by_xpath( "//input[@value='CREATE ACCOUNT']") login_btn.click() time.sleep(2) print(" >>> Account created!") write_file(r_mail, r_pas) except: print("Couldn't click!") time.sleep(1) driver.quit() except Exception as e: print(e)
def Accesos_web(rootDir, Ficheros_Respaldo): # DECLARACION DE VARIABLES Cod_Municipio = pd.DataFrame() Nombre_Municipio = '' # OBTIENE FICHERO XML tree = ET.parse(rootDir) root = tree.getroot() for each in root.findall('.//Datos_Emplazamiento'): dato_Cod_INE_Termino_Municipal = each.find( './/Cod_INE_Termino_Municipal') dato_Cod_INE_Provincia = each.find('.//Cod_INE_Provincia') dato_Referencia_Catastral = each.find('.//Referencia_Catastral') dato_Latitud = each.find('.//Latitud') dato_Longitud = each.find('.//Longitud') for each in root.findall('.//Calle'): dato_Poblacion = each.find('.//Poblacion') dato_Tipo_Via = each.find('.//Tipo_Via') dato_Nombre_Via = each.find('.//Nombre_Via') dato_Numero_Portal = each.find('.//Numero_Portal') # IMPORTAMOS CSV INE Cod_Municipio = pd.read_csv(os.path.join(Ficheros_Respaldo, 'Cod_Municipio_Prov.csv'), sep=';', encoding='latin1') # FILTRAMOS DATEFRAME CON CODIGOS INE EN BASE A DATOS XML Cod_Municipio = Cod_Municipio[Cod_Municipio['Cod_Municipio_Ine'] == dato_Cod_INE_Termino_Municipal.text] Cod_Municipio = Cod_Municipio[Cod_Municipio['Cod_Provincia_INE'] == int( dato_Cod_INE_Provincia.text)] # SI DATEDRAME VACIO NO SE PUEDE SACAR LOS DATOS CATASTRO if Cod_Municipio.empty: # GENERAR CSV RECHAZO COD PROVINCIA MUNICIPIO print("ERROR") # sacamos cod provincia y cod muninicipio catastro for Cod_Municipio_Catastro in Cod_Municipio['Cod_Municipio_Catastro']: Codigo_Municipio_Catastro = Cod_Municipio_Catastro for Cod_Provincia_Catastro in Cod_Municipio['Cod_Provincia_Catastro']: Codigo_Provincia_Catastro = Cod_Provincia_Catastro driver = webdriver.Firefox(executable_path=os.path.join( 'D:/EMR_Auditorias_Python/Ficheros_Respaldo', 'geckodriver.exe')) try: driver.get( "https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCConCiud.aspx?UrbRus=U&RefC=" + dato_Referencia_Catastral.text + "&esBice=&RCBice1=&RCBice2=&DenoBice=&from=OVCBusqueda&pest=rc&RCCompleta=" + dato_Referencia_Catastral.text + "&final=&del=" + str(Codigo_Provincia_Catastro) + "&mun=" + str(Codigo_Municipio_Catastro)) # leemos datos devueltos por catastro select = driver.find_element_by_xpath( "/html/body/form/fieldset/div[2]/div[2]/div[2]/div/div[1]/div[2]/div/div[2]/div/span/label" ) # obtenemos los datos Datos_Direccion_Catastro = select.text print(" referencia catastral ok") # comprobamos si son correctos los datos de catastro contra los de xml except: # codigo catastro erroneo, crear reparo print("ERROR codigo catastro") pass # Opens a new tab driver.execute_script("window.open()") # Switch to the newly opened tab driver.switch_to.window(driver.window_handles[1]) # Navigate to new URL in new tab driver.get("https://geoportal.minetur.gob.es/VCTEL/vcne.do") # sacamos provincia try: for N_Provincia in Cod_Municipio['Nombre Provincia']: Nombre_Provincia = N_Provincia # BUSCAMOS PROVICIA select = Select(driver.find_element_by_id('lstProvincias')) select.select_by_visible_text(Nombre_Provincia) # sacamos municipio for N_M_Catastro in Cod_Municipio['Nombre Municipio_Catastro']: Nombre_Municipio_Catastro = N_M_Catastro # BUSCAMOS MUNICIPIO select = Select(driver.find_element_by_id('listmuni')) select.select_by_visible_text(Nombre_Municipio_Catastro) print("OK municipio coincide con combo infoantenas") except: print("ERROR datos de municipio no coincide con combo infoantenas") pass try: # BUSCAMOS CALLE select = driver.find_element_by_id('nom_calle') select.send_keys(dato_Nombre_Via.text) select.send_keys(Keys.RETURN) print("Busqueda de la calle oK ") except: print("ERROR al realizar la busqueda de la calle") pass try: # METEMS ZOOM A MAPA time.sleep(2) driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() driver.find_element_by_id( 'OpenLayers.Control.PanZoomBar_59_zoomin_innerImage').click() # leer texto OpenLayers.Control.MousePosition_18 select = driver.find_element_by_id( 'OpenLayers.Control.MousePosition_18') Coordenadas = select.text # limpiamos y convertimos en array Coordenadas = Coordenadas.replace('ETRS89:', '') Coordenadas = Coordenadas.replace(' ', '') Coordenadas = Coordenadas.replace('N', '') Coordenadas = Coordenadas.replace('O', '') # con array coordenadoas crear funcion que reste coordenadas web y xml y segun resultado click en flecha de forma recursiva # xpath mapa: //*[@id="OpenLayers.Layer.Vector.RootContainer_33_svgRoot"] except: print("error problemas al manipular el mapa") pass # Run other commands in the new tab here # Opens a new tab driver.execute_script("window.open()") # Switch to the newly opened tab driver.switch_to.window(driver.window_handles[2]) # Navigate to new URL in new tab driver.get("https://www.ign.es/iberpix2/visor/") # Run other commands in the new tab here time.sleep(10) try: select = driver.find_element_by_xpath( "/html/body/ign-map/div/menu-routecal/div/div[1]/div/input") select.send_keys(dato_Tipo_Via.text + " " + dato_Nombre_Via.text + " " + dato_Numero_Portal.text + ", " + Nombre_Municipio_Catastro + ", " + Nombre_Provincia) time.sleep(4) # falta arreglar que pulse en la primera opcion # select.sendKeys(Keys.DOWN).sendKeys(Keys.ENTER) print("busqueda de calle ok") except: print("Error al hacer la busqueda en iberpix") pass """ #verson de buscueda por coordenadas, problema para meer coordenanda en combo try: select=driver.find_element_by_xpath('/html/body/ign-map/menu-toolbar/div/div[1]/paper-menu-button[1]/div/paper-button/span').click() select=driver.find_element_by_xpath('//*[@id="buttonShowPanelSearch"]').click() select=driver.find_element_by_xpath('/html/body/ign-map/search-component2/div/panel-component/div/iron-collapse/div/paper-tabs/div/div/paper-tab[2]/div').click() #metemos las coordenadas select=driver.find_element_by_id('searchLonGradesGeo2') #print(select.text) #select.send_keys("1") select=driver.find_element_by_xpath('//*[@id="buttonSearchByGeoCoord"]').click() print("busqueda de calle ok") except: print("Error al hacer la busqueda en iberpix") pass """ # Esta comentado por que habre ventana pero se queda pensando el programa , no termina. # falta cerrar ventana emergente y meter datos # Opens a new tab driver.execute_script("window.open()") # Switch to the newly opened tab driver.switch_to.window(driver.window_handles[3]) # Navigate to new URL in new tab driver.get("https://mapas.fomento.gob.es/VisorSIU/") time.sleep(2) try: select = driver.find_element_by_xpath( '/html/body/div[2]/div[1]/div[3]/div[2]/div[2]/div[2]/button' ).click() select = driver.find_element_by_xpath( '//*[@id="esri_dijit_Search_0_input"]') select.send_keys(dato_Tipo_Via.text + " " + dato_Nombre_Via.text + " " + dato_Numero_Portal.text + ", " + Nombre_Municipio_Catastro + ", " + Nombre_Provincia) select.submit() print("OK busqueda de calle") # no se puede obtener el tipo de suelo que es por que hay que pulsar en el punto except: print("ERROR al hacer la busqueda en web de fomento") pass