How to use click_if_visible method in SeleniumBase

Best Python code snippet using SeleniumBase

utility.py

Source:utility.py Github

copy

Full Screen

...48 default_handle = driver.current_window_handle49 handles = list(driver.window_handles)50 handles.remove(default_handle)51 driver.switch_to_window(handles[0])52def click_if_visible(self, element):53 driver = self.driver54 try:55 driver.find_element_by_id(element).click()56 except NoSuchElementException:57 pass58def click_if_clicable(self, element):59 driver = self.driver60 if driver.find_element_by_xpath(element).is_displayed():61 driver.find_element_by_xpath(element).click()62def verify_coupons(self, nameDrug):63 navigatePrescriptionSet(self, nameDrug)64 verify_coupons_no_nav(self, nameDrug)65def verify_coupons_no_nav(self, nameDrug):66 driver = self.driver67 main_page = driver.current_window_handle68 prices = driver.find_elements_by_xpath(strings.prices)69 coupons = driver.find_elements_by_xpath(strings.coupons)70 stores = driver.find_elements_by_xpath(strings.stores)71 pr = []72 coup = []73 st = []74 regex = re.compile(strings.regex)75 regex_stores = re.compile(strings.regex_stores)76 for el in prices:77 if 'after coupon' in el.text:78 pr.append(re.search(regex, el.text).group())79 for i in range(len(coupons)):80 if 'GET FREE' in coupons[i].text:81 coup.append(coupons[i])82 st.append(re.search(regex_stores, stores[i].text).group())83 for i in range(len(coup)):84 coup[i].click()85 click_if_visible(self, strings.getfreecoupon)86 click_if_visible(self, strings.proceedtodiscountid)87 # time.sleep(2)88 page_has_loaded(self)89 if "chrome" in driver.name:90 switch_window(self, i+1)91 if "firefox" in driver.name:92 windowswitcher(self)93 try:94 price = driver.find_element_by_xpath(strings.coupon_price).text95 company_name = driver.find_element_by_xpath(strings.coupon_store).text96 if price in pr[i]:97 print("<p>\n Verified founded the price: $" + price + " is same as in coupon and in coupon page \n</p>")98 assert True99 else:100 assert False101 if st[i] in company_name:102 print("<p>\n Verified founded the company name: " + st[i] + " is same as in coupon and in coupon page \n</p>")103 assert True104 else:105 print(st[i])106 assert False107 except NoSuchElementException:108 print("\n<p> Price or Company name not included for: "+nameDrug+ "\n</p>")109 pass110 driver.switch_to.window(main_page)111def navigatePrescriptionSet(self, nameDrug):112 driver = self.driver113 driver.get(strings.base_url)114 add_cookie(self)115 utility.wait_until_element_clicable(self, strings.search_box)116 click_first_search(self,strings.search_box,nameDrug,"1")117 utility.wait_until_element_clicable(self, strings.prices)118 assertIfElementDisplyed(self, strings.prices)119def assertIfElementDisplyed(self, element):120 driver = self.driver121 el = driver.find_element_by_xpath(element)122 assert el.is_displayed()123def selectOptionPresSet(self, option, index):124 driver = self.driver125 click_if_visible(self,strings.but_okgotit)126 try:127 utility.wait_until_element_clicable(self, option)128 driver.find_element_by_xpath(option).click()129 utility.wait_until_element_clicable(self, strings.option_elememnts +"["+index+"]")130 driver.find_element_by_xpath(strings.option_elememnts +"["+index+"]").click()131 utility.wait_until_element_clicable(self, strings.prices_coupons_page)132 except NoSuchElementException:133 pass134def ifdiscontinued_found_verify_coupons(self, nameDrug):135 driver = self.driver136 try:137 if 'is no longer available' in driver.find_element_by_xpath(strings.discontinued_drug).text:138 print(driver.find_element_by_xpath(strings.discontinued_drug).text)139 assert True140 except NoSuchElementException:141 verify_coupons_no_nav(self, nameDrug)142def customQuanPresSet(self, text):143 driver = self.driver144 click_if_visible(self,strings.but_okgotit)145 utility.wait_until_element_clicable(self, strings.option_quantity)146 driver.find_element_by_xpath(strings.option_quantity).click()147 utility.wait_until_element_clicable(self, strings.option_quantity_cus)148 driver.find_element_by_xpath(strings.option_quantity_cus).send_keys(text)149 utility.wait_until_element_clicable(self, strings.option_quantity_cus_set)150 driver.find_element_by_xpath(strings.option_quantity_cus_set).click()151 utility.wait_until_element_clicable(self, strings.prices_coupons_page)152def verify_coupon_custom(self, name, option, index):153 utility.navigatePrescriptionSet(self, name)154 utility.selectOptionPresSet(self, option, index)155 utility.ifdiscontinued_found_verify_coupons(self, name)156def verify_coupon_custom_quan(self, name, quan):157 utility.navigatePrescriptionSet(self, name)158 utility.customQuanPresSet(self, quan)...

Full Screen

Full Screen

hh1.py

Source:hh1.py Github

copy

Full Screen

...13 self.type('input[name="q"]', "hermanherry")14 self.sleep(1)15 self.highlight("div.sbic", loops=2, scroll=False)16 self.sleep(10)17 self.click_if_visible("div.sbic")18 self.sleep(5)19 self.execute_script("window.scrollBy(0, 2878)")20 self.highlight("div.GNJvt", loops=2, scroll=False)21 self.click_if_visible("div.GNJvt")22 self.execute_script("window.scrollBy(0, 2998)")23 self.sleep(10)24 self.highlight('a[href*="https://hermanherry.id/"]', loops=3)25 self.click('a[href*="https://hermanherry.id/"]')26 self.sleep(10)27 self.highlight("#aswift_2_expand", loops=4, scroll=True)28 self.click_if_visible('#aswift_2_expand')29 self.execute_script("window.scrollBy(0, 988)")30 self.sleep(10)31 self.open("https://google.com/ncr")32 self.highlight('input[name="q"]', loops=3)33 self.type('input[name="q"]', "hermanherry")34 self.sleep(1)35 self.highlight("div.sbic", loops=2, scroll=False)36 self.sleep(10)37 self.click_if_visible("div.sbic")38 self.sleep(5)39 self.execute_script("window.scrollBy(0, 2878)")40 self.highlight("div.GNJvt", loops=2, scroll=False)41 self.click_if_visible("div.GNJvt")42 self.execute_script("window.scrollBy(0, 2998)")43 self.sleep(10)44 self.highlight('a[href*="https://hermanherry.id/"]', loops=3)45 self.click('a[href*="https://hermanherry.id/"]')46 self.sleep(10)47 self.highlight("#aswift_3_expand", loops=4, scroll=True)48 self.click_if_visible('#aswift_3_expand')49 self.execute_script("window.scrollBy(0, 988)")50 self.sleep(10)51 self.open("https://google.com/ncr")52 self.highlight('input[name="q"]', loops=3)53 self.type('input[name="q"]', "hermanherry")54 self.sleep(1)55 self.highlight("div.sbic", loops=2, scroll=False)56 self.sleep(10)57 self.click_if_visible("div.sbic")58 self.sleep(5)59 self.execute_script("window.scrollBy(0, 2878)")60 self.highlight("div.GNJvt", loops=2, scroll=False)61 self.click_if_visible("div.GNJvt")62 self.execute_script("window.scrollBy(0, 2998)")63 self.sleep(10)64 self.highlight('a[href*="https://hermanherry.id/"]', loops=3)65 self.click('a[href*="https://hermanherry.id/"]')66 self.sleep(10)67 self.highlight("#aswift_4_expand", loops=4, scroll=True)68 self.click_if_visible('#aswift_4_expand')69 self.execute_script("window.scrollBy(0, 988)")70 self.sleep(10)71 self.open("https://google.com/ncr")72 self.highlight('input[name="q"]', loops=3)73 self.type('input[name="q"]', "hermanherry")74 self.sleep(1)75 self.highlight("div.sbic", loops=2, scroll=False)76 self.sleep(10)77 self.click_if_visible("div.sbic")78 self.sleep(5)79 self.execute_script("window.scrollBy(0, 2878)")80 self.highlight("div.GNJvt", loops=2, scroll=False)81 self.click_if_visible("div.GNJvt")82 self.execute_script("window.scrollBy(0, 2998)")83 self.sleep(10)84 self.highlight('a[href*="https://hermanherry.id/"]', loops=3)85 self.click('a[href*="https://hermanherry.id/"]')86 self.sleep(10)87 self.highlight("#aswift_1_expand", loops=4, scroll=True)88 self.click_if_visible('#aswift_1_expand')89 self.execute_script("window.scrollBy(0, 988)")90 self.sleep(10)91 self.open("https://google.com/ncr")92 self.highlight('input[name="q"]', loops=3)93 self.type('input[name="q"]', "hermanherry")94 self.sleep(1)95 self.highlight("div.sbic", loops=2, scroll=False)96 self.sleep(10)97 self.click_if_visible("div.sbic")98 self.sleep(5)99 self.execute_script("window.scrollBy(0, 2878)")100 self.highlight("div.GNJvt", loops=2, scroll=False)101 self.click_if_visible("div.GNJvt")102 self.execute_script("window.scrollBy(0, 2998)")103 self.sleep(10)104 self.highlight('a[href*="https://hermanherry.id/"]', loops=3)105 self.click('a[href*="https://hermanherry.id/"]')106 self.sleep(10)107 self.highlight("#aswift_1_expand", loops=4, scroll=True)...

Full Screen

Full Screen

LoginPage.py

Source:LoginPage.py Github

copy

Full Screen

...9 super().__init__(driver, wait, actions)10 def login(self):11 self.sending_keys(LoginPage.email, enter_your_login_id)12 def continue_click(self):13 self.click_if_visible(LoginPage.continue_button)14 def password_filed(self):15 self.sending_keys(LoginPage.password, enter_your_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 SeleniumBase 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