Best Python code snippet using elementium_python
se.py
Source: se.py
...288 if wait:289 return elements.until(lambda e: len(e) > 0, ttl=ttl)290 else:291 return elements292 def find_with_wait(self, selector, only_displayed=True, ttl=None):293 """Find the elements that match the given selector with waiting294 This is equivalent to calling find() with ``wait=True``.295 :param selector: The selector to use296 :param only_displayed: Whether or not to only return elements that297 are displayed298 :param ttl: The minimum number of seconds to keep retrying299 :returns: An :class:`Elements` object containing the web elements that300 match the :attr:`selector`301 """302 s = self.find(303 selector, only_displayed=only_displayed, wait=True, ttl=ttl)304 if only_displayed:305 s.insist(lambda e: e.is_displayed())306 else:...
selcad.py
Source: selcad.py
...57options = Options()58options.page_load_strategy = 'eager'59options.add_experimental_option("debuggerAddress", f"127.0.0.1:{debug_port}")60driver = webdriver.Chrome(options=options, service=Service(executable_path='/home/gui/selcad/chromedriver'))61def find_with_wait(xpath):62 return WebDriverWait(driver, timeout=DONT_CARE_WAIT).until(EC.element_to_be_clickable((By.XPATH, xpath)))63def find_with_wait2(xpath):64 return WebDriverWait(driver, timeout=DONT_CARE_WAIT).until(EC.element_located_to_be_selected((By.XPATH, xpath)))65def find_with_wait3(xpath):66 return WebDriverWait(driver, timeout=DONT_CARE_WAIT).until(EC.presence_of_element_located((By.XPATH, xpath)))67def find_with_wait4(xpath):68 return WebDriverWait(driver, timeout=DONT_CARE_WAIT).until(EC.visibility_of_element_located((By.XPATH, xpath)))69# url70def get_cadastre_until_it_opens():71 driver.get("https://cadastre.mimt.gov.ir")72 # refresh until we find username box73 while True:74 try:75 WebDriverWait(driver, timeout=0.5).until(76 EC.presence_of_element_located((By.XPATH, '//*[@id="ULogin1_txt_Username"]')))77 break78 except (TimeoutException, UnexpectedAlertPresentException):79 # driver.get("https://cadastre.mimt.gov.ir/")80 driver.refresh()81# get_cadastre_until_it_opens()82def get_sms():83 return subprocess.Popen(['nc', '-ln', '0.0.0.0', '38587'], stdout=subprocess.PIPE).communicate()[0].decode()84# login85def login():86 find_with_wait('//*[@id="ULogin1_txt_Username"]').send_keys(username)87 driver.find_element(By.XPATH, '//*[@id="ULogin1_txt_Pass"]').send_keys(password)88 WebDriverWait(driver, timeout=DONT_CARE_WAIT).until(89 EC.presence_of_element_located((By.XPATH, '//*[@id="ULogin1_BtnNewRequest"]')))90 # captcha91 # captcha_element = find_with_wait4('//*[@id="ctl00_ULogin1_RadCaptcha1_CaptchaImageUP"]')92 # captcha_element.screenshot(captcha_element.id+'.png')93 # captcha = get_captcha_from_user_using_tk(captcha_element.id+'.png')94 # driver.find_element(By.XPATH, '//*[@id="ctl00_ULogin1_RadCaptcha1_CaptchaTextBox"]').send_keys(captcha)95 # driver.find_element(By.XPATH, '//*[@id="ULogin1_btnLogin1"]').click()96 # sms97 # sms=get_sms()98 # print(sms)99 # find_with_wait('//*[@id="ULogin1_txtSMSCode"]').send_keys(get_sms())100 # driver.find_element(By.XPATH, '//*[@id="ULogin1_txtSMSCode"]').send_keys(sms)101 # find_with_wait('//*[@id="ULogin1_btnSMSLogin"]').click()102 # driver.find_element(By.XPATH, '//*[@id="ULogin1_btnSMSLogin"]').click()103# login()104# everything starts from here. >105driver.get("https://cadastre.mimt.gov.ir/Map/RegMap.aspx")106def select_from_menu(xpath, item):107 find_with_wait(xpath).click()108 item_list = find_with_wait(xpath[:-7] + 'DropDown"]/div/ul').find_elements(By.TAG_NAME, 'li')109 for elem in item_list:110 if elem.get_attribute('innerHTML') == item:111 # todo: advance wait112 sleep(TINY_WAIT)113 elem.click()114 # driver.execute_script("arguments[0].click();", elem)115 break116# step 1: select province117def select_province():118 select_from_menu('//*[@id="ctl00_ContentPlaceHolder1_CmbEstate_Input"]', province)119 # refresh if we stuck120 while True:121 try:122 WebDriverWait(driver, timeout=IMPORTANT_WAIT).until(123 EC.invisibility_of_element_located((By.CLASS_NAME, 'raDiv')))124 break125 except TimeoutException:126 driver.refresh()127 select_from_menu('//*[@id="ctl00_ContentPlaceHolder1_CmbEstate_Input"]', province)128 sleep(TINY_WAIT)129select_province()130# step 2: mineral matrial131# select group6132def select_mineral_material():133 select_from_menu('//*[@id="ctl00_ContentPlaceHolder1_CmbGroup_Input"]', 'گرÙÙ 6')134 # refresh if we stuck135 while True:136 try:137 WebDriverWait(driver, timeout=IMPORTANT_WAIT).until(138 EC.invisibility_of_element_located((By.CLASS_NAME, 'raDiv')))139 break140 except TimeoutException:141 driver.refresh()142 # TODO: idk this is needed or not143 select_province()144 select_from_menu('//*[@id="ctl00_ContentPlaceHolder1_CmbGroup_Input"]', 'گرÙÙ 6')145 sleep(TINY_WAIT)146select_mineral_material()147def select_metal():148 while True:149 try:150 # ... button151 find_with_wait('//*[@id="ctl00_ContentPlaceHolder1_RadButton1_input"]').click()152 break153 except ElementClickInterceptedException:154 sleep(TINY_WAIT)155 # TODO: idk this is needed or not156 # select kansar felezi (but refresh if we stuck)157 while True:158 try:159 driver.switch_to.frame(WebDriverWait(driver, timeout=IMPORTANT_WAIT).until(160 EC.visibility_of_element_located((By.TAG_NAME, "iframe"))))161 break162 except TimeoutException:163 driver.refresh()164 # TODO: idk this is needed or not165 select_province()166 select_mineral_material()167 # driver.switch_to.frame(driver.find_element(By.TAG_NAME,"iframe"))168 find_with_wait('/html/body/form/div[4]/div/div[2]/table/tbody/tr[3]/td[3]').click()169 # taeed170 find_with_wait('//*[@id="RadButton1_input"]').click()171 driver.switch_to.default_content()172 sleep(TINY_WAIT)173select_metal()174# step 3: insert points175def insert_points(points):176 for point in points:177 xd = find_with_wait3('//*[@id="ctl00_ContentPlaceHolder1_LngD"]')178 xm = find_with_wait3('//*[@id="ctl00_ContentPlaceHolder1_LngM"]')179 xs = find_with_wait3('//*[@id="ctl00_ContentPlaceHolder1_LngS"]')180 yd = find_with_wait3('//*[@id="ctl00_ContentPlaceHolder1_LatD"]')181 ym = find_with_wait3('//*[@id="ctl00_ContentPlaceHolder1_LatM"]')182 ys = find_with_wait3('//*[@id="ctl00_ContentPlaceHolder1_LatS"]')183 xd.clear()184 xm.clear()...
Check out the latest blogs from LambdaTest on this topic:
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
Software Risk Management (SRM) combines a set of tools, processes, and methods for managing risks in the software development lifecycle. In SRM, we want to make informed decisions about what can go wrong at various levels within a company (e.g., business, project, and software related).
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!