How to use select_by_text method in Selene

Best Python code snippet using selene_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...40 self.headers = {41 'X-NCP-APIGW-API-KEY-ID': 'm11ogby6ag',42 'X-NCP-APIGW-API-KEY': 'G8nc8zH5sP4pg8ZVMYETnLoReXCfx04vgNKvwsPE',43 }44 def select_by_text(self, select, text):45 if text is None or len(text)==0:46 return 47 text = text.replace(' ', '')48 for index, option in enumerate(select.options):49 if text in option.text:50 select.select_by_index(index)51 # self.wait_for_load()52 return 53 def select_by_random(self, select):54 if len(select.options) > 1:55 random_int = random.randint(1, len(select.options)-1)56 select.select_by_index(random_int)57 self.wait_for_load()58 def wait_for_load(self):59 driver = self.driver60 WebDriverWait(driver, 10).until(EC.staleness_of(driver.find_element_by_css_selector('div.blockPage')))61 62 def remove_empty_objs(self, unfiltered_list):63 return list(filter(lambda info: len(info['longName'])!=0, unfiltered_list))64 def find_obj(self, target_list, key, value):65 return next( (obj for obj in target_list if obj[key][0]==value), None)66 def get_value(self, obj, key):67 if obj is not None:68 return obj[key]69 # def get_key_by_value(self, obj, value):70 # return [ obj]71 # def remove_blank(self, string):72 # return string.replace(' ', '')73 def lookup_geocode(self, address):74 url = self.geocode_url+address75 response = requests.get(url, headers=self.headers)76 response_json = response.json()77 # return {78 # 'lng': response['addresses'][0]['x'],79 # 'lat': response['addresses'][0]['y']80 # }81 if response.status_code == 200 and response_json['status'] == 'OK':82 if response_json['meta']['totalCount']>0:83 return response_json['addresses'][0]84 else:85 raise Exception('검색 결과가 없습니다.')86 else:87 raise Exception('정상적인 응답을 받지 못했습니다.')88 # step 1. 입력된 주소값을 Naver Geocode API로 조회89 # step 2. 정상적으로 조회된 결과가 존재하면 해당 지번 주소를 농사로 페이지에 입력 후 결과를 크롤링90 def lookup_nongsaro(self, address):91 driver = self.driver92 try:93 searched_address = self.lookup_geocode(address)94 geo_position = {95 'lng': searched_address['x'],96 'lat': searched_address['y']97 }98 address_elements = searched_address['addressElements']99 except Exception as e:100 raise e101 filtered_list = self.remove_empty_objs(address_elements)102 sido_text = self.get_value( self.find_obj(filtered_list, 'types', 'SIDO'), 'longName' )103 sigungu_text = self.get_value( self.find_obj(filtered_list, 'types', 'SIGUGUN'), 'longName' )104 townMyeonDong_text = self.get_value( self.find_obj(filtered_list, 'types', 'DONGMYUN'), 'longName' )105 ri_text = self.get_value( self.find_obj(filtered_list, 'types', 'RI'), 'longName' )106 jibn_text = self.get_value( self.find_obj(filtered_list, 'types', 'LAND_NUMBER'), 'longName' )107 # self.select_by_text(self.sido_select, sido_text)108 # self.select_by_text(self.sigungu_select, sigungu_text)109 # self.select_by_text(self.townMyeonDong_select, townMyeonDong_text)110 # self.select_by_text(self.ri_select, ri_text)111 # self.select_by_text(self.jibn_select, jibn_text)112 self.select_by_text(self.sido_select, sido_text)113 if sido_text=='세종특별자치시':114 raise Exception('농사로 토양검정정보에서 세종특별자치시가 저장되지 않았습니다.')115 else:116 WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#siGunGuLst > option:nth-child(2)")))117 self.select_by_text(self.sigungu_select, sigungu_text)118 WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#townMyeonDongLst > option:nth-child(2)")))119 self.select_by_text(self.townMyeonDong_select, townMyeonDong_text)120 if townMyeonDong_text[-1]=='동':121 pass122 else:123 WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#riLst > option:nth-child(2)")))124 self.select_by_text(self.ri_select, ri_text)125 WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#jibn_tr")))126 self.select_by_text(self.jibn_select, jibn_text)127# WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#jibun_div")))128 WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="jibun_div"]/div[4]')))129 # address = driver.find_element_by_xpath('//*[@id="jibun_div"]/div[2]/table/tbody/tr/td').text130 aptitude_div = driver.find_element_by_xpath('//*[@id="jibun_div"]/div[4]')131 soup = bs(aptitude_div.get_attribute('innerHTML'), features="html.parser")132 133 response = {134 'address': searched_address['jibunAddress'],135 'aptitude_table': str(soup).replace('\n', ''),136 **geo_position,137 }...

Full Screen

Full Screen

test_calculator.py

Source:test_calculator.py Github

copy

Full Screen

...26 app.x_input.send_keys('-45.083')27 app.y_input.send_keys('-12')28 assert app.result.value == '-57.083'29 def test_subtraction(self, app):30 app.operations.select_by_text('X-Y')31 app.x_input.send_keys('104')32 app.y_input.send_keys('24')33 assert app.result.value == '80'34 app.x_input.send_keys('-24')35 app.y_input.send_keys('24.31')36 assert app.result.value == '-48.31'37 app.x_input.send_keys('10,23')38 app.y_input.send_keys('-75')39 assert app.result.value == '85.23'40 app.x_input.send_keys('-3')41 app.y_input.send_keys('-7')42 assert app.result.value == '4'43 def test_multiplication(self, app):44 app.operations.select_by_text('X*Y')45 app.x_input.send_keys('0,25')46 app.y_input.send_keys('0,25')47 assert app.result.value == '0.0625'48 app.x_input.send_keys('1e2')49 app.y_input.send_keys('0.002')50 assert app.result.value == '0.2'51 app.x_input.send_keys('8')52 app.y_input.send_keys('2')53 assert app.result.value == '16'54 app.x_input.send_keys('6')55 app.y_input.send_keys('-2')56 assert app.result.value == '-12'57 def test_deviation(self, app):58 app.operations.select_by_text('X/Y')59 app.x_input.send_keys('-248')60 app.y_input.send_keys('-2')61 assert app.result.value == '124'62 app.x_input.send_keys('02')63 app.y_input.send_keys('2')64 assert app.result.value == '1'65 app.x_input.send_keys('0.5')66 app.y_input.send_keys('2')67 assert app.result.value == '0.25'68 app.x_input.send_keys('2.0')69 app.y_input.send_keys('4.0')70 assert app.result.value == '0.5'71 def test_make_all_operations_for_same_x_y(self, app):72 app.x_input.send_keys('+100')73 app.y_input.send_keys('100')74 app.operations.select_by_text('X+Y')75 assert app.result.value == '200'76 app.operations.select_by_text('X-Y')77 assert app.result.value == '0'78 app.operations.select_by_text('X/Y')79 assert app.result.value == '1'80 app.operations.select_by_text('X*Y')81 assert app.result.value == '10000'82 def test_handling_infinity(self, app):83 app.x_input.send_keys('1e2')84 app.y_input.send_keys('0')85 app.operations.select_by_text('X/Y')86 assert app.result.value == 'Infinity'87 app.y_input.send_keys('1')88 assert app.result.value == '100'89 app.x_input.send_keys('Infinity')90 assert app.result.value == 'Infinity'91 app.operations.select_by_text('X-Y')92 assert app.result.value == 'Infinity'93 app.operations.select_by_text('X+Y')94 assert app.result.value == 'Infinity'95 app.operations.select_by_text('X*Y')96 assert app.result.value == 'Infinity'97 app.y_input.send_keys('0')98 assert app.result.value == 'NaN'99 app.y_input.send_keys('Infinity')100 assert app.result.value == 'Infinity'101 app.x_input.send_keys('-1')102 assert app.result.value == '-Infinity'103 app.operations.select_by_text('X-Y')104 assert app.result.value == '-Infinity'105 app.operations.select_by_text('X+Y')106 assert app.result.value == 'Infinity'107 app.operations.select_by_text('X*Y')108 assert app.result.value == '-Infinity'109 def test_put_forbbiden_sign_to_x_input(self, app):110 app.x_input.send_keys('NaN')111 app.y_input.send_keys('3')112 app.operations.select_by_text('X+Y')113 assert app.x_input.value == 'NaN'114 assert app.result.value == 'NaN'115 app.operations.select_by_text('X-Y')116 assert app.x_input.value == 'NaN'117 assert app.result.value == 'NaN'118 app.operations.select_by_text('X*Y')119 assert app.x_input.value == 'NaN'120 assert app.result.value == 'NaN'121 app.operations.select_by_text('X/Y')122 assert app.x_input.value == 'NaN'123 assert app.result.value == 'NaN'124 app.x_input.send_keys('300')125 assert app.result.value == '100'126 def test_put_forbbiden_sign_to_y_input(self, app):127 app.x_input.send_keys('-0')128 app.y_input.send_keys('&')129 app.operations.select_by_text('X+Y')130 assert app.y_input.value == '&'131 assert app.result.value == 'NaN'132 app.operations.select_by_text('X-Y')133 assert app.y_input.value == '&'134 assert app.result.value == 'NaN'135 app.operations.select_by_text('X*Y')136 assert app.y_input.value == '&'137 assert app.result.value == 'NaN'138 app.operations.select_by_text('X/Y')139 assert app.y_input.value == '&'140 assert app.result.value == 'NaN'141 app.y_input.send_keys('200')...

Full Screen

Full Screen

e2e.py

Source:e2e.py Github

copy

Full Screen

...19def create_contact(driver, name, phone, username, group_name, backend_name):20 driver.open('/admin/rapidsms/contact/')21 driver.browser.click_link_by_partial_text('Add contact')22 driver.browser.fill("name", name)23 driver.select_by_text('user', username)24 driver.select_by_text('groups', group_name)25 driver.browser.fill('birthdate_0', '2013-02-22')26 driver.browser.fill('birthdate_1', '12:55:40')27 driver.select_by_text('gender', 'Male')28 driver.select_by_text('connection_set-0-backend', backend_name)29 driver.browser.fill("connection_set-0-identity", phone)30 driver.browser.find_by_name('_save').click()31class SplinterE2E(LiveServerTestCase):32 def __init__(self, methodName='runTest'):33 super(SplinterE2E, self).__init__(methodName)34 def follow_link(self, text):35 (self.browser.find_element_by_link_text(text)).click()36 def select_by_text(self, name, text):37 self.browser.find_by_xpath(38 '//select[@name="%s"]/option[normalize-space(.)="%s"]' % (name, text)).first._element.click()39 def create_and_sign_in_admin(self,username,password):40 self.open('/accounts/login')41 self.browser.fill("username", username)42 self.browser.fill("password", password)43 self.browser.find_by_css("input[type=submit]").first.click()44 def open(self, url):45 host_and_port = [re.split("=",index)[1] for index in sys.argv if re.match("target_host", index) is not None]46 if not len(host_and_port):47 print "Host and Port not specified. Use ./manage.py test <path_to_test_file> <target_host = x.x.x.x:port_number>\n"48 print "Using: 127.0.0.1:8000 as default host and port configuration"49 host_and_port = ["127.0.0.1:8000"]50 self.browser.visit("%s%s" % ("http://%s" % host_and_port[0], url))51 def wait_for_seconds(self, time_out_in_seconds):52 current_time = datetime.datetime.now()53 end_time = current_time + datetime.timedelta(0, time_out_in_seconds)54 while current_time < end_time:55 current_time = datetime.datetime.now()56BROWSER = Browser('firefox')57class UreportE2ETest(SplinterE2E):58 def setUp(self):59 self.browser = BROWSER60 self.open('/')61 def tearDown(self):62 self.open('/account/logout')63 def create_poll(self,group_name):64 self.open('/createpoll/')65 self.browser.fill("name", "%s" % "foo")66 self.browser.fill("question_en", "bar")67 self.select_by_text('groups', group_name)68 self.browser.find_by_id('createPoll').first.click()69 def should_match_poll_question_to_message_text(self):70 username = "ureport"71 password = "ureport"72 self.create_and_sign_in_admin(username,password)73 group_name="group_name"74 backend_name = "dmark"75 create_backend(self,backend_name)76 create_group(self, group_name)77 create_contact(self, "name", '235454432',username,group_name, backend_name)78 self.create_poll(group_name)79 self.browser.find_link_by_text('Start Poll').first.click()80 assert self.browser.is_text_present('Close Poll')81 connection = psycopg2.connect("dbname=ureport","user=Admin","host=10.48.4.31","password=")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful