How to use all_by method in Selene

Best Python code snippet using selene_python

locators.py

Source:locators.py Github

copy

Full Screen

1import time2from selenium.webdriver.common.by import By3from selenium.common.exceptions import NoSuchElementException4from selenium.webdriver.support import expected_conditions as EC5from selenium.webdriver.support.wait import WebDriverWait6# -----------------7# Locator functions8# -----------------9def element_clickeable(self, by, what):10 all_by= locator_element_test(by)11 element = WebDriverWait(self.driver, 10).until(12 EC.element_to_be_clickable((all_by, what)))13 return element14def element_located(self,by, what):15 all_by = locator_element_test(by)16 element = WebDriverWait(self.driver, 10).until(17 EC.presence_of_element_located((all_by,what)))18 return element19def locator_element_test(locator_type):20 """Find an element and return it"""21 time.sleep(0.5)22 if str(locator_type).upper() == 'ID':23 by = By.ID24 elif str(locator_type).upper() == 'NAME':25 by = By.NAME26 elif str(locator_type).upper() == 'XPATH':27 by = By.XPATH28 elif str(locator_type).upper() == 'CSS':29 by = By.CSS_SELECTOR30 elif str(locator_type).upper() == 'LINK':31 by = By.LINK_TEXT32 elif str(locator_type).upper() == 'CLASS_NAME':33 by = By.CLASS_NAME34 return by35def locator_elements(self, locator_type, locator):36 """Find set of elements and return them"""37 time.sleep(0.5)38 if str(locator_type).upper() == 'ID':39 by = By.ID40 elif str(locator_type).upper() == 'NAME':41 by = By.NAME42 elif str(locator_type).upper() == 'XPATH':43 by = By.XPATH44 elif str(locator_type).upper() == 'CSS':45 by = By.CSS_SELECTOR46 elif str(locator_type).upper() == 'LINK':47 by = By.LINK_TEXT48 elif str(locator_type).upper() == 'CLASS_NAME':49 by = By.CLASS_NAME50 return self.driver.find_elements(by, locator)51def locator_elements(self, locator_type, locator):52 """Find set of elements and return them"""53 time.sleep(0.5)54 if str(locator_type).upper() == 'ID':55 by = By.ID56 elif str(locator_type).upper() == 'NAME':57 by = By.NAME58 elif str(locator_type).upper() == 'XPATH':59 by = By.XPATH60 elif str(locator_type).upper() == 'CSS':61 by = By.CSS_SELECTOR62 elif str(locator_type).upper() == 'LINK':63 by = By.LINK_TEXT64 elif str(locator_type).upper() == 'CLASS_NAME':65 by = By.CLASS_NAME66 return self.driver.find_elements(by, locator)67def element_exists(self, locator_type, locator):68 element = locator_elements(self,locator_type,locator)69 if len(element) > 0:70 return True71 else:72 return False73def highlight(self, element):74 """Highlights (blinks) a Selenium Webdriver element"""75 try:76 def apply_style(s):77 self.driver.execute_script("arguments[0].setAttribute('style', arguments[1]);", element, s)78 original_style = element.get_attribute('style')79 apply_style("background: yellow; border: 2px solid red;")80 time.sleep(0.3)81 apply_style(original_style)82 except:83 return84# ----------------------------------85# Attributes and properties functions86# ----------------------------------87# def get_attribute_value(self, locator_type, locator, attribute):88# element = element_located(self, locator_type, locator)89# attribute_value = element.get_attribute(attribute)90# return attribute_value91#92#93# def get_all_attributes(self, locator_type, locator):94# element = element_located(self, locator_type, locator)95# attrs = []96# for attr in element.get_property('attributes'):97# attrs.append([attr['name'], attr['value']])...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

...10uow = UnitOfWork()11active = 'admin_dashboard'12def index(request):13 today = datetime.date.today()14 orders_month = uow.orders.all_by(15 payment_date__year=today.year,16 payment_date__month=today.month17 )18 startdate = today - datetime.timedelta(days=today.weekday())19 enddate = startdate + datetime.timedelta(days=6)20 orders_week = uow.orders.all_by(21 payment_date__gte=startdate,22 payment_date__lte=enddate23 )24 month_total = sum([order.total for order in orders_month])25 week_total = sum([order.total for order in orders_week])26 orders_for_refund = list(uow.orders.all_by(27 state=states.ORDER_REQUESTED_REFUND))28 # Test29 week_total = 3345.1530 month_total = 125728.4831 return render(request, 'dashboard/index.html', {32 'orders_week': orders_week,33 'orders_month': orders_month,34 'orders_for_refund': orders_for_refund,35 'month_total': month_total,36 'week_total': week_total,37 'active': active,38 })39# API calls40def total_progress(request):41 today = datetime.date.today()42 orders_month = uow.orders.all_by(43 payment_date__year=today.year,44 payment_date__month=today.month45 )46 month_total = sum([order.total for order in orders_month])47 progress = (month_total / EARNING_GOAL) * 10048 # Test49 progress = 12050 return JsonResponse({'message': 'ok', 'data': progress})51def week_earnings_day(request):52 days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']53 today = datetime.date.today()54 dt = datetime.date.today() - datetime.timedelta(days=today.weekday())55 day_earnings = {}56 for day in days:57 orders_day = uow.orders.all_by(58 payment_date__year=dt.year,59 payment_date__month=dt.month,60 payment_date__day=dt.day,61 )62 day_earnings[day] = sum([order.total for order in orders_day])63 dt = dt + datetime.timedelta(days=1)64 # Test data65 for day in days:66 day_earnings[day] = random.randint(10, 100)67 return JsonResponse({'message': 'ok', 'data': day_earnings})68def get_featured_products(request):69 featured = uow.trackings.objects.values('product__id', 'product__name', 'product__small_img') \70 .annotate(Sum('quantity')) \71 .order_by('-quantity__sum')[:5]72 featured_list = list(featured)73 featured_response = [74 {75 'id': featured['product__id'],76 'product': featured['product__name'],77 'quantity': featured['quantity__sum'],78 'small_img': featured['product__small_img'],79 }80 for featured in featured_list]81 return JsonResponse({'message': 'ok', 'data': featured_response})82def orders_state(request):83 states = [state[0] for state in list(84 uow.orders.objects.order_by().values_list('state').distinct())]85 states_response = []86 for state in states:87 count = uow.orders.all_by(state=state).count()88 states_response.append({'state': state, 'count': count})...

Full Screen

Full Screen

l2_카펫.py

Source:l2_카펫.py Github

copy

Full Screen

1def solution(brown, yellow):2 sqaure = brown + yellow3 4 can_make = []5 6 print(sqaure)7 for a in range(1, int(sqaure**(1/2)+1)):8 b, check = divmod(sqaure, a)9 if check == 0:10 can_make.append((b, a))11 print(can_make)12 13 for a, b in can_make:14 print(a, b, brown)15 if 2*(a+b-2) == brown:16 print(a, b)17 return [a,b]18solution(10,2)19# def solution(brown, yellow):20# can_make = []21# all_by = brown+yellow22# for i in range(3, int((all_by)**0.5)+1):23# if (all_by) % i ==0:24# can_make.append((all_by//i, i))25# for m, n in can_make:26# if (m-2)*(n-2) == yellow:...

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