How to use maximize_window method in SeleniumBase

Best Python code snippet using SeleniumBase

online_shop.py

Source:online_shop.py Github

copy

Full Screen

1# 商品查詢器~2from selenium import webdriver3import pyautogui4# edge 的 webdriver 要依照版本來做更新!!5# 讓使用者輸入他要查的東西(目前所使用的為"蝦皮")6print("----------")7want = input("欲查詢的商品:")8if (want != ""):9 money_range = input("是否要開啟價格範圍(填入<是> or <否>):")10 if money_range == "是":11 miniprice = input("所需的最<低>價位:")12 maxprice = input("所需的最<高>價位:")13 elif money_range == "否":14 skip = "skip"15 else :16 print("所輸入的方式有誤")17 store = input("欲在哪裡搜尋(1.蝦皮、2.momo、3.露天、4.以上三者皆要)---輸入編號:")18 if (store == "1") or (store == "1."):19 if money_range == "否":20 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")21 driver.maximize_window22 driver.get(f"https://shopee.tw/search?keyword={want}")23 elif money_range == "是":24 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")25 driver.maximize_window26 driver.get(f"https://shopee.tw/search?keyword={want}&maxPrice={maxprice}&minPrice={miniprice}")27 else :28 print("所請求的方式不對,但仍幫你查找商品")29 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")30 driver.maximize_window31 driver.get(f"https://shopee.tw/search?keyword={want}")32 print("已成功協助搜尋")33 elif (store == "2") or (store == "2."):34 if money_range == "否":35 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")36 driver.maximize_window37 driver.get(f"https://www.momoshop.com.tw/search/searchShop.jsp?keyword={want}")38 elif money_range == "是":39 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")40 driver.maximize_window41 driver.get(f"https://www.momoshop.com.tw/search/searchShop.jsp?keyword={want}&_advPriceS={miniprice}&_advPriceE={maxprice}")42 else :43 print("所請求的方式不對,但仍幫你查找商品")44 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")45 driver.maximize_window46 driver.get(f"https://www.momoshop.com.tw/search/searchShop.jsp?keyword={want}")47 print("已成功協助搜尋")48 elif (store == "3") or (store == "3."):49 if money_range == "否":50 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")51 driver.maximize_window52 driver.get(f"https://www.ruten.com.tw/find/?q={want}")53 elif money_range == "是":54 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")55 driver.maximize_window56 driver.get(f"https://www.ruten.com.tw/find/?q={want}&prc.now={miniprice}-{maxprice}")57 else :58 print("所請求的方式不對,但仍幫你查找商品")59 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")60 driver.maximize_window61 driver.get(f"https://www.ruten.com.tw/find/?q={want}")62 print("已成功協助搜尋")63 elif (store == "4") or (store == "4."):64 page = 165 if money_range == "否":66 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")67 driver.maximize_window68 driver.get(f"https://shopee.tw/search?keyword={want}")69 #[1]:按下 Ctrl + T 來新增分頁,而且要搭配pyautogui70 pyautogui.hotkey('ctrl', 't', interval=0.1) #[1]71 #[2]:切換瀏覽器的window handle72 driver.switch_to.window(driver.window_handles[page]) #[2]73 #[3]:page記得+174 page+=1 #[3]75 driver.get(f"https://www.momoshop.com.tw/search/searchShop.jsp?keyword={want}")76 pyautogui.hotkey('ctrl', 't', interval=0.1)77 driver.switch_to.window(driver.window_handles[page])78 driver.get(f"https://www.ruten.com.tw/find/?q={want}")79 elif money_range == "是":80 driver = webdriver.Edge(executable_path="X:\\edge_driver\\msedgedriver.exe")81 driver.maximize_window82 driver.get(f"https://shopee.tw/search?keyword={want}&maxPrice={maxprice}&minPrice={miniprice}")83 pyautogui.hotkey('ctrl', 't', interval=0.1)84 driver.switch_to.window(driver.window_handles[page])85 page+=186 driver.get(f"https://www.momoshop.com.tw/search/searchShop.jsp?keyword={want}&_advPriceS={miniprice}&_advPriceE={maxprice}")87 pyautogui.hotkey('ctrl', 't', interval=0.1)88 driver.switch_to.window(driver.window_handles[page])89 driver.get(f"https://www.ruten.com.tw/find/?q={want}&prc.now={miniprice}-{maxprice}")90 print("已成功協助搜尋")91 else :92 print("目前無提供此類商城來搜尋,或者是您的輸入有誤~")...

Full Screen

Full Screen

Base.py

Source:Base.py Github

copy

Full Screen

...1516 self.driver = ''17 if Web_Browser == "Mozilla Firefox":18 self.driver = webdriver.Firefox()19 self.driver.maximize_window()2021 elif Web_Browser == "Google Chrome":22 self.driver =\23 webdriver.Chrome(24 pathToChromedriver25 )26 self.driver.maximize_window()2728 elif Web_Browser == "Internet Explorer 32":29 self.driver =\30 webdriver.Ie(31 pathToIEDriverServer_Win3232 )33 self.driver.maximize_window()3435 elif Web_Browser == "Internet Explorer 64":36 self.driver =\37 webdriver.Ie(38 pathToIEDriverServer_x6439 )40 self.driver.maximize_window()4142 elif Web_Browser == "Android Chrome":43 capabilities = {44 'chromeOptions': {45 'androidPackage': 'com.android.chrome',46 }47 }48 self.driver = webdriver.Remote('http://' + server + ':9515/wd/hub',49 capabilities)5051 elif Web_Browser == "Android Chrome Remote":52 capabilities = {53 'chromeOptions': {54 'androidPackage': 'com.android.chrome',55 }56 }57 self.driver = webdriver.Remote(remoteURL,58 capabilities)5960 elif Web_Browser == "Mozilla Firefox Grid local":61 self.driver = webdriver.Remote(62 command_executor=gridURL,63 desired_capabilities={64 "browserName": "firefox",65 "version": "38.0.1",66 })67 self.driver.maximize_window()6869 elif Web_Browser == "Mozilla Firefox Grid remote":70 self.driver = webdriver.Remote(71 command_executor=gridURL,72 desired_capabilities={73 "browserName": "firefox",74 "version": "38.0.1 remote",75 })76 self.driver.maximize_window()7778 elif Web_Browser == "Google Chrome Grid local":79 self.driver = webdriver.Remote(80 command_executor=gridURL,81 desired_capabilities={82 "browserName": "chrome",83 "version": "42.0.2311.152 m (64-bit)",84 })85 self.driver.maximize_window()8687 elif Web_Browser == "Google Chrome Grid remote":88 self.driver = webdriver.Remote(89 command_executor=gridURL,90 desired_capabilities={91 "browserName": "chrome",92 "version": "42.0.2311.152 m remote",93 })94 self.driver.maximize_window()9596 elif Web_Browser == "Internet Explorer Grid local":97 self.driver = webdriver.Remote(98 command_executor=gridURL,99 desired_capabilities={100 "browserName": "internet explorer",101 "version": "11.0 X64",102 })103 self.driver.maximize_window()104105 elif Web_Browser == "Internet Explorer Grid remote":106 self.driver = webdriver.Remote(107 command_executor=gridURL,108 desired_capabilities={109 "browserName": "internet explorer",110 "version": "11.0 Win32",111 })112 self.driver.maximize_window()113114 elif Web_Browser == "Android Chrome Grid local":115 self.driver = webdriver.Remote(116 command_executor=gridURL,117 desired_capabilities={118 'chromeOptions': {119 'androidPackage': 'com.android.chrome',120 },121 "browserName": "chrome",122 "platform": "WINDOWS",123 "version": "android local"124 })125126 elif Web_Browser == "Android Chrome Grid remote": ...

Full Screen

Full Screen

conftest.py

Source:conftest.py Github

copy

Full Screen

...4"""5@pytest.fixture6def setUp():7 driver = webdriver.Chrome('D:\driver\chromedriver_win32\chromedriver.exe')8 driver.maximize_window()9 return driver10 11 """12'''13@pytest.fixture14def setUp():15 #driver = webdriver.Chrome('D:\driver\chromedriver_win32\chromedriver.exe')16 driver = webdriver.Firefox(executable_path="D:\\driver\\geckodriver.exe")17 driver.maximize_window()18 return driver19 20 '''21'''22@pytest.fixture23def setUp():24 # driver = webdriver.Chrome('D:\driver\chromedriver_win32\chromedriver.exe')25 driver = webdriver.Ie(executable_path="D:\\driver\\IEDriverServer.exe")26 driver.maximize_window()27 return driver28 29 '''30# @pytest.fixture31# def setUp(browser):32# if browser == 'chrome':33# #driver = webdriver.Chrome('D:\driver\chromedriver_win32\chromedriver.exe')34# # D:\driver\driver_version\chromedriver_win32 (1)\chromedriver.exe35#36# driver = webdriver.Chrome('D:\driver\driver_version\chromedriver_win32 (1)\chromedriver.exe')37# driver.maximize_window()38# print("launching chrome driver")39#40# elif browser == 'firefox':41# driver = webdriver.Firefox(executable_path="D:\\driver\\geckodriver.exe")42# driver.maximize_window()43# print("launching firefox driver")44#45# else:46# driver = webdriver.Ie(executable_path="D:\\driver\\IEDriverServer.exe")47# driver.maximize_window()48# return driver49#50#51# def pytest_addoption(parser):52# parser.addoption("--browser")53#54#55# @pytest.fixture56# def browser(request):57# return request.config.getoption("--browser")58########### pytest HTML Report ################59'''60# It is hook for Adding Environment info to HTML Report61def pytest_configure(config):62 config._metadata['Project Name'] = 'nop Commerce'63 config._metadata['Module Name'] = 'Customers'64 config._metadata['Tester'] = 'Pavan'65# It is hook for delete/Modify Environment info to HTML Report66@pytest.mark.optionalhook67def pytest_metadata(metadata):68 metadata.pop("JAVA_HOME", None)69 metadata.pop("Plugins", None)70 71 '''72@pytest.fixture73def setUp(browser):74 if browser == 'chrome':75 parent_dir = os.getcwd()76 directory = '\\configuration\\chromedriver.exe'77 path = parent_dir + directory78 driver = webdriver.Chrome(path)79 driver.maximize_window()80 print("launching chrome driver")81 elif browser == 'firefox':82 parent_dir = os.getcwd()83 directory = '\\configuration\\geckodriver.exe'84 path = parent_dir + directory85 driver = webdriver.Firefox(executable_path=path)86 driver.maximize_window()87 print("launching firefox driver")88 else:89 parent_dir = os.getcwd()90 directory = '\\configuration\\IEDriverServer.exe'91 path = parent_dir + directory92 driver = webdriver.Ie(executable_path=path)93 driver.maximize_window()94 print("launching IE driver")95 return driver96def pytest_addoption(parser):97 parser.addoption("--browser")98@pytest.fixture99def browser(request):...

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