How to use switch_to_default_window method in SeleniumBase

Best Python code snippet using SeleniumBase

add_ao_vpn.py

Source:add_ao_vpn.py Github

copy

Full Screen

...19from bs4 import BeautifulSoup20212223def switch_to_default_window(driver):24 all_handles = driver.window_handles25 current_handle = driver.current_window_handle26 for handle in all_handles:27 if handle != current_handle:28 driver.switch_to.window(handle)29class login(object):30 Address_Objects = (By.LINK_TEXT,"Address Objects")3132 def __init__(self):33 self.driver = webdriver.Firefox()3435 '''36 def switch_to_default_window(cls):373839 cls.driver.switch_to.default_content()40 all_handle = cls.driver.window_handles41 current_handle = cls.driver.current_window_handle42 for handle in all_handle:43 if handle != current_handle:44 cls.driver.switch_to.window(handle)45 '''4647 def login_web(self):48 base_url = self.base_url = "https://10.8.43.60/"49 driver = self.driver50 driver.implicitly_wait(30)51 driver.maximize_window()52# base_url = "http://10.8.42.2/"53 driver.get(base_url + "auth.html")54# driver.switch_to.window("SonicWall Administrator")55 driver.switch_to.frame("authFrm")56 driver.find_element_by_name("userName").clear()57 driver.find_element_by_name("userName").send_keys("admin")58 driver.find_element_by_name("pwd").clear()59 driver.find_element_by_name("pwd").send_keys("password")60 driver.find_element_by_name("Submit").click()616263 def logout(self):64 self.driver.quit()6566 def switch_to_Network(self):67 driver = self.driver68 driver.switch_to.default_content()69 driver.switch_to.frame("outlookFrame")70 driver.find_element_by_link_text("Network").click()71# address_objects = self.driver.find_element('Network')72# driver.execute_script("arguments[0].click();", address_objects)73 time.sleep(2)7475 def switch_to_vpn(self):76 driver = self.driver77 driver.switch_to.default_content()78 driver.switch_to.frame("outlookFrame")79 driver.find_element_by_link_text("VPN").click()8081 def switch_to_settings(self):82 driver = self.driver83 driver.switch_to.default_content()84 driver.switch_to.frame('outlookFrame')85 button = driver.find_element_by_link_text('Settings')86 driver.execute_script("arguments[0].click();", button)87 time.sleep(4)8889 def switch_to_firewall_Settings(self):90 driver = self.driver91 driver.switch_to.default_content()92 driver.switch_to.frame('outlookFrame')93 button = driver.find_element_by_link_text('Firewall Settings')94 driver.execute_script('arguments[0].click()', button)95 time.sleep(2)9697 def switch_to_default_window(self):98 driver = self.driver99 all_handles = driver.window_handles100 current_handle = driver.current_window_handle101 for handle in all_handles:102 if handle != current_handle:103 driver.switch_to.window(handle)104105 def switch_window(self, windowname):106 driver = self.driver107 driver.maximize_window()108 driver.switch_to.default_content()109 all_handles = driver.window_handles110 for handle in all_handles:111 driver.switch_to.window(handle)112 if driver.title == windowname:113 driver.switch_to.window(handle)114 break115 print driver.title116117 def test_add_ao(self):118 driver = self.driver119 driver.switch_to.default_content()120 self.switch_to_Network()121 driver.find_element_by_link_text("Address Objects").click()122 time.sleep(2)123 driver.switch_to.default_content()124 driver.switch_to.frame("tabFrame")125 time.sleep(2)126 button = driver.find_element_by_id("addAoBtn")127 driver.execute_script("arguments[0].click();", button)128 # driver.find_element_by_id("addAoBtn").click()129 # ERROR: Caught exception [ERROR: Unsupported command [waitForPopUp | 10_8_42_58_addrObjdlg | 30000]]130 # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=10_8_42_58_addrObjdlg | ]]131 time.sleep(2)132# driver.switch_to.window("Add Address Object")133 self.switch_window("Add Address Object")134 driver.find_element_by_name('noName').clear()135 driver.find_element_by_name('noName').send_keys('testvsss58668')136 Select(driver.find_element_by_name("zone")).select_by_visible_text("LAN")137 Select(driver.find_element_by_name("noType")).select_by_visible_text("Range")138 driver.find_element_by_id("noIp1").clear()139 driver.find_element_by_id("noIp1").send_keys("9.9.9.9")140 driver.find_element_by_id("noIp2").clear()141 driver.find_element_by_id("noIp2").send_keys("9.9.9.99")142 button = driver.find_element_by_id("actionBtn0")143 driver.execute_script("arguments[0].click();", button)144 time.sleep(2)145 driver.find_element_by_name('noName').clear()146 driver.find_element_by_name('noName').send_keys('testvsss5668')147 '''148 Select(driver.find_element_by_name("zone")).select_by_visible_text("VPN")149 Select(driver.find_element_by_name("noType")).select_by_visible_text("Range")150 '''151 driver.find_element_by_name('noType').find_element_by_xpath("//option[@value='VPN']").click()152 Select(driver.find_element_by_name("noType")).select_by_visible_text("Range")153 select = driver.find_element_by_tag_name('select')154 all_options = select.find_elements_by_tag_name('option')155 for option in all_options:156 print option157 driver.find_element_by_id("noIp1").clear()158 driver.find_element_by_id("noIp1").send_keys("99.99.9.9")159 driver.find_element_by_id("noIp2").clear()160 driver.find_element_by_id("noIp2").send_keys("99.99.9.99")161 button = driver.find_element_by_id("actionBtn0")162 driver.execute_script("arguments[0].click();", button)163 time.sleep(2)164165166167 button1 = driver.find_element_by_id("closeBtn0")168 driver.execute_script("arguments[0].click();", button1)169 print driver.current_url170 driver.close()171 driver.refresh()172173174 # self.switch_to_default_window()175 driver.switch_to.default_content()176 print driver.title177 handles = driver.window_handles178 handle1 = driver.current_window_handle179 print handles[1]180 print len(handles)181 print handle1182 for handle in handles:183 print 'test'184 if handle != handle1:185 driver.switch_to.window(handle)186 print driver.title187 else:188 driver.find_element_by_id("closeBtn0").click()189190191192193194195196197 def add_vpn_policy(self):198 print 'test.dsdafas'199 driver = self.driver200 driver.switch_to.default_content()201 self.switch_to_vpn()202 print 'testdds'203# driver.find_element_by_link_text("Settings").click()204 driver.switch_to.default_content()205 driver.switch_to.frame("tabFrame")206 time.sleep(2)207 # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=tabFrame | ]]208 button = driver.find_element_by_name("addVpnPolBtn")209 driver.execute_script("arguments[0].click();", button)210 time.sleep(2)211 self.switch_window("VPN Policy")212213 # ERROR: Caught exception [ERROR: Unsupported command [waitForPopUp | 10_8_42_58_dialogScroll | 30000]]214 # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=10_8_42_58_dialogScroll | ]]215 # driver.find_element_by_id("t1Label").click()216 driver.find_element_by_id("ipsecName").clear()217 driver.find_element_by_id("ipsecName").send_keys('vpn_policy_s2s')218 driver.find_element_by_id("ipsecGwAddr").clear()219 driver.find_element_by_id("ipsecGwAddr").send_keys('10.8.42.24')220 driver.find_element_by_id("ipsecIkePskCtl").clear()221 driver.find_element_by_id('ipsecIkePskCtl').send_keys('111111')222 driver.find_element_by_id('confirmPsk').clear()223 driver.find_element_by_id('confirmPsk').send_keys('111111')224 driver.find_element_by_id("t1Label").click()225 Select(driver.find_element_by_name("ipsecLocalNetwork")).select_by_visible_text("testvsss58668")226 Select(driver.find_element_by_name("ipsecRemoteNetwork")).select_by_visible_text("testvsss5668")227228229 driver.find_element_by_id("t2Label").click()230231 driver.find_element_by_id("t3Label").click()232 driver.find_element_by_id("ipsecKeepAlive").click()233 driver.find_element_by_id("ipsecHttpsUsrLogin").click()234 driver.find_element_by_id("ipsecHttpsMgmt").click()235 driver.find_element_by_name("ok").click()236 time.sleep(3)237 print 'dddddaaaaaaaaaaaadddddd'238 handles = driver.window_handles239 handle1 = driver.current_window_handle240# switch_to_default_window(driver)241 for handle in handles:242 driver.switch_to.window(handle)243 if handle != handle1:244 driver.switch_to.window(handle)245 print driver.title246247 def test_upload_firmware(self):248 driver = self.driver249 self.switch_to_settings()250251 driver.switch_to.default_content()252 driver.switch_to.frame("tabFrame")253 driver.find_element_by_xpath(".//*[@id='thisForm']/table[8]/tbody/tr[5]/td/input[1]").click()254 time.sleep(2)255 self.switch_window('SonicWall - Upload Firmware')256# driver.find_element_by_css_selector("input.button").click()257# driver.find_element_by_name("firmware").clear()258# driver.find_element_by_name("firmware").send_keys("D:\\vmware-operate\\sw_tz-300_eng_6.5.0.0_6.5.0_5n_987910.sig")259# driver.find_element_by_name("ok").click()260 upload = driver.find_element_by_name('firmware')261 upload.click()262 '''263 SendKeys.SendKeys('////\\\\10.190.202.40\Firmware\NG\\6.5.0.0-5n\TZ-300\sw_tz-300_eng_6.5.0.0_6.5.0_5n_987910.sig')264 SendKeys.SendKeys('{ENTER}')265 '''266 time.sleep(2)267 # win32268 diaglog = win32gui.FindWindow('#32770', u'文件上传')269 print diaglog270 ComboBoxEx32 = win32gui.FindWindowEx(diaglog, 0, 'ComboBoxEx32', None)271 print ComboBoxEx32272 ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, 'ComboBox', None)273 Edit = win32gui.FindWindowEx(ComboBox, 0, 'Edit', None)274 print Edit275 button = win32gui.FindWindowEx(diaglog, 0, 'Button', None)276 print button277 time.sleep(1)278 win32gui.SendMessage(Edit, win32con.WM_SETTEXT, None, '\\\\10.190.202.40\\Firmware\\NG\\6.2.7.7-2n\\TZ-600\\sw_tz-600_eng_6.2.7.7_6.2.7.7_2n_974136.sig')279 time.sleep(1)280 win32gui.SendMessage(diaglog, win32con.WM_COMMAND, 1, button)281 time.sleep(1)282 '''283 b = win32gui.GetDlgItem(diaglog, 2)284 print b285 win32gui.SendMessage(diaglog, win32con.WM_COMMAND, 2, b)286 '''287 #driver.switch_to.default_window()288 # win32gui.SendMessage(diaglog, win32con.WM_CLOSE)289 driver.find_element_by_name("ok").click()290291 self.switch_to_default_window()292293 '''294 handle1 = driver.current_window_handle295 print handle1296 handles = driver.window_handles297 print driver.title298 print handles299 for handle in handles:300 #driver.switch_to.window(handle)301 if handle != handle1:302 driver.switch_to.window(handle)303304305 time.sleep(20)306 print driver.title307 '''308309 def test_boot_new_firmware(self):310 driver = self.driver311 self.switch_to_settings()312313 driver.switch_to.default_content()314 driver.switch_to.frame("tabFrame")315# driver.find_element_by_xpath(".//*[@id='thisForm']/table[8]/tbody/tr[8]/td/input[1]").click()316# time.sleep(2)317# self.switch_window('SonicWall - Upload Firmware')318# driver.find_element_by_css_selector("input.button").click()319# driver.find_element_by_name("firmware").clear()320# driver.find_element_by_name("firmware").send_keys("D:\\vmware-operate\\sw_tz-300_eng_6.5.0.0_6.5.0_5n_987910.sig")321# driver.find_element_by_name("ok").click()322 '''323 driver.find_element_by_xpath(".//*[@id='thisForm']/table[8]/tbody/tr[8]/td/input[1]").click()324 time.sleep(2)325326 self.switch_window('SonicWall - Upload Firmware')327 upload = driver.find_element_by_name('firmware')328 upload.click()329# SendKeys.SendKeys('////\\\\10.190.202.40\\Firmware\\NG\\6.2.7.7-2n\\TZ-600\\sw_tz-600_eng_6.2.7.7_6.2.7.7_2n_974136.sig')330# SendKeys.SendKeys('{ENTER}')331 diaglog = win32gui.FindWindow('#32770', u'文件上传')332 print diaglog333 ComboBoxEx32 = win32gui.FindWindowEx(diaglog, 0, 'ComboBoxEx32', None)334 print ComboBoxEx32335 ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, 'ComboBox', None)336 Edit = win32gui.FindWindowEx(ComboBox, 0, 'Edit', None)337 print Edit338 button = win32gui.FindWindowEx(diaglog, 0, 'Button', None)339 print button340 time.sleep(1)341 win32gui.SendMessage(Edit, win32con.WM_SETTEXT, None, '\\\\10.190.202.40\\Firmware\\NG\\6.2.7.7-2n\\TZ-600\\sw_tz-600_eng_6.2.7.7_6.2.7.7_2n_974136.sig')342 time.sleep(1)343 win32gui.SendMessage(diaglog, win32con.WM_COMMAND, 1, button)344 driver.find_element_by_name("ok").click()345 time.sleep(20)346 '''347 try:348 button = driver.find_element_by_xpath(".//*[@id='thisForm']/table[8]/tbody/tr[5]/td[6]/a/img")349 driver.execute_script("arguments[0].click();", button)350 time.sleep(2)351 alert = driver.switch_to.alert352 alert.accept()353 alert1 = driver.switch_to.alert354 alert1.accept()355 except:356 print 'please upload the new firmware'357 self.switch_to_default_window()358 return False359360361 def test_export_pref(self):362 driver = self.driver363 self.switch_to_settings()364 driver.switch_to.default_content()365 driver.switch_to.frame("tabFrame")366 driver.find_element_by_xpath(".//*[@id='thisForm']/table[4]/tbody/tr/td[2]/input").click()367368 self.switch_window('Export Settings')369 driver.find_element_by_name("ok").click()370 time.sleep(6)371 print 'teeees'372 '''373 SendKeys.SendKeys('{TAB}')374 print 'dddd'375 SendKeys.SendKeys('{TAB}')376 SendKeys.SendKeys('{TAB}')377 print 'dsdfasdf'378 '''379 SendKeys.SendKeys('{ENTER}')380 print 'ddddd'381382383384 '''385 SendKeys.SendKeys('{ENTER}')386 print 'ggg'387 time.sleep(2)388 SendKeys.SendKeys('{ENTER}')389 print 'tesdss'390 dialog = win32gui.FindWindow('MozillaDialogClass', u'正在打开 sonicwall-TZ_600-6_2_7_1-23n.exp')391 print dialog392 button = win32gui.FindWindowEx(dialog, 0, 'Button', None)393 print button394 win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button)395 '''396397 def test_enable_firewall_settings(self):398 driver = self.driver399 print driver.get_cookies()400 self.switch_to_firewall_Settings()401 driver.switch_to.default_content()402 driver.switch_to.frame("tabFrame")403 try:404 inputs = driver.find_elements_by_tag_name('input')405 for input in inputs:406 if input.get_attribute('type') == 'checkbox':407 input.click()408 time.sleep(1)409 except:410 driver.get_screenshot_as_png("D:\\vmware-operate\\screenshot\\firewall_setting.png")411 '''412 html = driver.page_source413 soup = BeautifulSoup(html, "lxml")414 test = soup.find_all('label')415416 lst1 = []417 for i in range(0, len(test)):418 # print str(test[i])419 lst1.append(str(test[i]))420 print lst1421 print len(lst1)422 # for i in range(0, len(lst1)):423 print lst1[i]424425 test1 = soup.find_all('input')426 lst2=[]427 for i in range(0, len(test1)):428 if 'checkbox' in str(test1[i]) or 'radio' in str(test1[i]):429 lst2.append(str(test1[i]))430 print lst2431 print len(lst2)432 dict1 = dict(zip(lst2, lst1))433 print dict1434 # for key, value in dict1.iteritems():435 # print key, value436 '''437 print driver.find_element_by_id('enableStealthMode0').is_selected()438 if driver.find_element_by_id('enableStealthMode0').is_selected():439 pass440 else:441 driver.find_element_by_id('enableStealthMode0').click()442 driver.find_element_by_id('DecrementHopLimit0').click()443 driver.find_elements_by_css_selector('input[type=checkbox]').pop().click()444 time.sleep(2)445446447 time.sleep(2)448 button = driver.find_element_by_name('applyButt')449 driver.execute_script("arguments[0].click()", button)450 self.switch_to_default_window()451452453454455456457test = login()458test.login_web()459#test.test_enable_firewall_settings()460#test.test_add_ao()461#test.test_upload_firmware()462#test.switch_to_default_window()463test.add_vpn_policy()464#test.test_upload_firmware()465test.test_enable_firewall_settings()466if test.test_boot_new_firmware() == False:467 test.test_upload_firmware()468 test.test_boot_new_firmware()469else:470 test.test_boot_new_firmware()471#test.test_enable_firewall_settings() ...

Full Screen

Full Screen

TESTCASE_Search.py

Source:TESTCASE_Search.py Github

copy

Full Screen

...51 OverviewSearch.Profile.POFS_PO_ISSUE_DATE.click()52 53 switch_to_new_window()54 import_module_dynamic("OverviewSearchDatePicker")55 switch_to_default_window()56 57 58 OverviewSearch.Profile.POFS_SEARCH.click()59 60 OverviewSearchResult = import_module_dynamic("OverviewSearchResult")61 OverviewSearchResult.Profile.POFS_DETAIL.click()62 time.sleep(2)63 switch_to_new_window()64 OverviewSearchResultDetail = import_module_dynamic("OverviewSearchResultDetail")65 Assert().assert_equal(OverviewSearchResultDetail.Profile.POFS_PONUMBER.text, "0000434")66 close_window()67 switch_to_default_window()68 69 70 time.sleep(2)71 72 73 #Stop and case and record the starting time74 Log.stop_test()75# def suite():76# suite = unittest.TestSuite()77# suite.addTest(TestCaseLogin('testCase001_Login'))78# suite.addTest(TestCaseSearch('testCase001_Login'))79# suite.addTest(TestCaseSearch('testCase002_Search'))80# 81# ...

Full Screen

Full Screen

case_pofs_search.py

Source:case_pofs_search.py Github

copy

Full Screen

...39 POFS_PO_ISSUE_DATE.click()40 41 Browser.switch_to_new_window()42 Element.date_picker(31, 1, 2008)43 Browser.switch_to_default_window()44 45 POFS_SEARCH = Element.find_element(By.NAME, u'submit')46 POFS_SEARCH.click()47 48 POFS_DETAIL = Element.find_element(By.XPATH, u'//img[@src="../images/detail.gif"]')49 POFS_DETAIL.click()50 Browser.switch_to_new_window()51 POFS_PONUMBER = Element.find_element(By.XPATH, u'//*[@id="printable"]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]')52 Assert().assert_equal(POFS_PONUMBER.text, "0000434")53 Browser.close_window()54 Browser.switch_to_default_window()55 56 Log.stop_test()57 58 @classmethod59 def tearDownClass(self):60 self.driver.quit()61if __name__ == "__main__":62 suite = unittest.TestSuite()63 suite.addTest(TestCaseSearch("test_case_search_001"))64 suite.addTest(TestCaseSearch("test_case_search_002"))65 unittest.TextTestRunner().run(suite)66 ...

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