How to use get_window_height method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

main_yt.pyw

Source:main_yt.pyw Github

copy

Full Screen

...3031def get_window_width():32 window_width = int(width * 0.5 * get_scale_mult())33 return window_width34def get_window_height():35 window_height = int(height * 0.5 * get_scale_mult())36 return window_height37def get_window_size():38 window_size = str(get_window_width()) + "x" + str(get_window_height())39 return window_size4041#Set up window42def setup_window(): 43 root.resizable(0,0)44 root.geometry(get_window_size())45 root.configure(background="#2b2929")46 root.title("YouTube Video Downloader")4748#Create place to insert link WITH LABEL49link = StringVar()50def place_pastelink_text(): 51 paste_link_label = Label(52 root,53 text = 'Paste Link Below',54 font = 'arial ' + str(int(round(30 * get_scale_mult()))) + ' bold underline',55 background = '#2b2929',56 foreground = '#bd433c'57 )58 paste_link_x = int((get_window_width() - (360 * get_scale_mult())) / 2)59 paste_link_y = int(get_window_height() * 0.25)60 paste_link_label.place(x=paste_link_x, y=paste_link_y)6162#Insert link63def place_enterlink_text():64 link_enter = Entry(65 root, 66 width = int((70 * get_scale_mult())), 67 textvariable = link,68 background = "#ffffff"69 )70 link_enter_x = int((get_window_width() - (get_window_width() * 0.7)) / 2)71 link_enter_y = int(get_window_height() / 2)72 link_enter.place(x=link_enter_x, y=link_enter_y)7374#Fullscreen function75def Fullscreen():76 if root.state == False: #If not in fullscreen, change to fullscreen, change indicator to True, increase scale, destroy and replace buttons/labels.77 root.attributes("-fullscreen", True)78 root.state = True79 for widget in root.winfo_children():80 widget.destroy()81 init_func()82 83 else: #If already in fullscreen, change back to normal size, change indicator to False, decrease scale, destroy and replace buttons/labels.84 root.attributes("-fullscreen", False)85 root.state = False86 for widget in root.winfo_children():87 widget.destroy()88 init_func()8990#Main download function91def Download(): 92 try: #Valid Link93 url = YouTube(str(link.get()))94 video = url.streams.get_highest_resolution()95 video.download(output_path=path)96 downloaded_label = Label(97 root,98 text = 'DOWNLOADED', 99 font = 'arial ' + str(int(round(15 * get_scale_mult()))),100 background = '#2b2929',101 foreground = '#bd433c'102 )103 downloaded_label_x = int((get_window_width() - (get_window_width() * 0.2)) / 2)104 downloaded_label_y = int(get_window_height() * 0.9)105 downloaded_label.place(x=downloaded_label_x, y=downloaded_label_y)106 except: #Invalid Link107 fail_label = Label(108 root,109 text = '<<INVALID>>',110 font = 'arial ' + str(int(round(15 * get_scale_mult()))),111 background = '#2b2929',112 foreground = '#bd433c'113 )114 fail_label_x = int((get_window_width() - (get_window_width() * 0.2)) / 2)115 fail_label_y = int(get_window_height() * 0.9)116 fail_label.place(x=fail_label_x, y=fail_label_y)117118#Create Download Button 119def place_download_button():120 download_button = Button(121 root,122 height = 2,123 width = 20,124 text = 'DOWNLOAD',125 font = 'arial ' + str(int(round(15 * get_scale_mult()))) + ' bold' ,126 bg = '#bd433c', 127 padx = 2, 128 command = Download129 )130 dbutton_x = int((get_window_width() - (get_window_width() * 0.4)) / 2)131 dbutton_y = int(get_window_height() * 0.7)132 download_button.place(x=dbutton_x, y=dbutton_y)133134#Create fullscreen button135def place_fullscreen_button():136 fullscreen_button = Button(137 root,138 height = 1,139 width = 15,140 text = 'Toggle Fullscreen',141 font = 'arial 10 bold',142 bg = '#bd433c',143 padx = 2,144 command = Fullscreen145 )146 fbutton_x = 0147 fbutton_y = 0148 fullscreen_button.place(x=fbutton_x, y=fbutton_y)149150#Initial function to get values & place buttons151def init_func():152 get_scale_mult()153 get_window_width()154 get_window_height()155 get_window_size()156 setup_window()157 place_pastelink_text()158 place_enterlink_text()159 place_download_button()160 place_fullscreen_button()161162#Run program163if __name__ == "__main__":164 init_func() ...

Full Screen

Full Screen

selenium_scraper.py

Source:selenium_scraper.py Github

copy

Full Screen

1import time2from selenium.common.exceptions import JavascriptException3from selenium.webdriver import Chrome4from selenium.webdriver.chrome.options import Options5from selenium.webdriver.common.by import By6from selenium.webdriver.remote.webelement import WebElement7from crawling_wheel.data import result8from crawling_wheel.models import CatFood9class WebScrapper:10 options = Options()11 options.add_argument("--window-size=1545,1047")12 options.add_argument("--window-position=0,0")13 def __init__(self, brand_name, type_of_selector="XPATH"):14 self.driver = Chrome(options=self.options)15 self.driver.implicitly_wait(10)16 # self.driver.minimize_window()17 self.brand_name = brand_name18 self.url_list = result[brand_name]19 self.type_of_selector = type_of_selector20 self.result_list = []21 def execute(self, script: str):22 try:23 return self.driver.execute_script(script)24 except JavascriptException:25 time.sleep(3)26 return self.driver.execute(script)27 def set_attr(self, element_id: str, attr_to_on: str):28 self.execute(f"document.getElementById('{element_id}').setAttribute('{attr_to_on}','true');")29 def scroll_infinite(self):30 scroll_to_bottom = "window.scrollTo(0, document.body.scrollHeight);"31 get_window_height = "return document.body.scrollHeight"32 last_height = self.execute(get_window_height)33 while True:34 self.execute(scroll_to_bottom)35 time.sleep(3)36 new_height = self.execute(get_window_height)37 if new_height == last_height:38 break39 last_height = new_height40 def activate_class(self, element_id: str, show_class: str):41 return self.execute(f"document.getElementById('{element_id}').classList.add('{show_class}');")42 def activate_class_by_selector(self, selector: str, show_class: str):43 return self.execute(f"document.querySelector('{selector}').classList.add('{show_class}');")44 def scroll_to(self, element: WebElement):45 return self.driver.execute_script("arguments[0].scrollIntoView(false);", element)46 def click_element(self, selector):47 return self.execute(f"document.querySelector('{selector}').click().scrollIntoViewIfNeeded();")48 def get_text(self, selector):49 result_list = []50 if self.type_of_selector == "XPATH":51 targets = self.driver.find_elements(By.XPATH, selector)52 else:53 targets = self.driver.find_elements(By.CSS_SELECTOR, selector)54 if len(targets) == 0:55 return None56 elif len(targets) == 1:57 self.scroll_to(targets[0])58 return targets[0].text.replace("\n", "|")59 elif len(targets) > 1:60 self.scroll_to(targets[-1])61 for t in targets:62 if t.text:63 result_list.append(t.text.replace("\n", "|"))64 if len(result_list) == 1:65 return result_list[0]66 return result_list67 def crawl(self,68 INGREDIENTS='',69 ANALYSIS='',70 ADDITIVES='',71 CALORIE_CONTENT='',72 JAVASCRIPT='',73 ):74 for url in self.url_list:75 product = CatFood()76 product.brand = self.brand_name77 product.url = url78 self.driver.get(url)79 self.execute(JAVASCRIPT)80 time.sleep(2)81 product['title'] = self.driver.title82 if INGREDIENTS:83 product['ingredients'] = self.get_text(INGREDIENTS)84 if ANALYSIS:85 product['analysis'] = self.get_text(ANALYSIS)86 if ADDITIVES:87 product['additive'] = self.get_text(ADDITIVES)88 if CALORIE_CONTENT:89 product['calorie'] = self.get_text(CALORIE_CONTENT)90 print(product)91 self.result_list.append(product)...

Full Screen

Full Screen

window_dimensions.py

Source:window_dimensions.py Github

copy

Full Screen

1from game.scripts import get_window_width, get_window_height2from . import install_translator3# Add support for translating level config strings to window dimensions4install_translator('window_width', get_window_width)...

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 robotframework-appiumlibrary 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