2023-02-06, support Edge browser.

master
CHUN YU YAO 2023-02-08 00:42:04 +08:00
parent d9c2695fc4
commit c94e31f826
2 changed files with 65 additions and 10 deletions

View File

@ -389,12 +389,23 @@ def get_driver_by_config(config_dict, driver_type):
if browser == "firefox":
# default os is linux/mac
# download url: https://github.com/mozilla/geckodriver/releases
chromedriver_path = os.path.join(webdriver_path,"geckodriver")
if platform.system().lower()=="windows":
chromedriver_path = os.path.join(webdriver_path,"geckodriver.exe")
firefox_service = Service(chromedriver_path)
driver = webdriver.Firefox(service=firefox_service)
webdriver_service = Service(chromedriver_path)
driver = webdriver.Firefox(service=webdriver_service)
if browser == "edge":
# default os is linux/mac
# download url: https://developer.microsoft.com/zh-tw/microsoft-edge/tools/webdriver/
chromedriver_path = os.path.join(webdriver_path,"msedgedriver")
if platform.system().lower()=="windows":
chromedriver_path = os.path.join(webdriver_path,"msedgedriver.exe")
webdriver_service = Service(chromedriver_path)
driver = webdriver.Edge(service=webdriver_service)
#print("try to close opened tabs.")
'''
@ -5372,6 +5383,7 @@ def urbtix_performance_confirm_dialog_popup(driver):
return ret
def urbtix_main(driver, url, config_dict):
# http://msg.urbtix.hk
waiting_for_access_url = ['/session/landing-timer/','msg.urbtix.hk','busy.urbtix.hk']
@ -7201,7 +7213,7 @@ def main():
answer_index = -1
kktix_register_status_last = None
DISCONNECTED_MSG = 'Unable to evaluate script: no such window: target window already closed'
DISCONNECTED_MSG = ': target window already closed'
ocr = None
Captcha_Browser = None
@ -7244,14 +7256,26 @@ def main():
driver.switch_to.window(driver.window_handles[0])
driver.switch_to.default_content()
time.sleep(0.2)
else:
if DISCONNECTED_MSG in driver.get_log('driver')[-1]['message']:
except Exception as excSwithFail:
#print("excSwithFail:", excSwithFail)
pass
if window_handles_count==0:
try:
driver_log = driver.get_log('driver')[-1]['message']
print("get_log:", driver_log)
if DISCONNECTED_MSG in driver_log:
print('quit bot by NoSuchWindowException')
driver.quit()
sys.exit()
break
except Exception as excSwithFail:
pass
except Exception as excGetDriverMessageFail:
#print("excGetDriverMessageFail:", excGetDriverMessageFail)
except_string = str(excGetDriverMessageFail)
if 'HTTP method not allowed' in except_string:
print('quit bot by close browser')
driver.quit()
sys.exit()
break
except UnexpectedAlertPresentException as exc1:
# PS: DON'T remove this line.

View File

@ -19,7 +19,7 @@ import json
import webbrowser
import pyperclip
CONST_APP_VERSION = u"MaxBot (2023.02.05)"
CONST_APP_VERSION = u"MaxBot (2023.02.06)"
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
@ -43,6 +43,9 @@ URL_DONATE = 'https://max-everyday.com/about/#donate'
URL_HELP = 'https://max-everyday.com/2018/03/tixcraft-bot/'
URL_RELEASE = 'https://github.com/max32002/tixcraft_bot/releases'
URL_FB = 'https://www.facebook.com/maxbot.ticket'
URL_CHROME_DRIVER = 'https://chromedriver.chromium.org/'
URL_FIREFOX_DRIVER = 'https://github.com/mozilla/geckodriver/releases'
URL_EDGE_DRIVER = 'https://developer.microsoft.com/zh-tw/microsoft-edge/tools/webdriver/'
def load_translate():
translate = {}
@ -1563,7 +1566,7 @@ def AdvancedTab(root, config_dict, language_code, UI_PADDING_X):
global combo_browser
combo_browser = ttk.Combobox(frame_group_header, state="readonly")
combo_browser['values']= ("chrome","firefox")
combo_browser['values']= ("chrome","firefox","edge")
combo_browser.set(config_dict['browser'])
combo_browser.grid(column=1, row=group_row_count, sticky = W)
@ -1776,6 +1779,34 @@ def AboutTab(root, language_code):
lbl_fb_fans_url.grid(column=1, row=group_row_count, sticky = W)
lbl_fb_fans_url.bind("<Button-1>", lambda e: open_url(URL_FB))
group_row_count +=1
lbl_chrome_driver = Label(frame_group_header, text=u'Chrome Driver')
lbl_chrome_driver.grid(column=0, row=group_row_count, sticky = E)
lbl_chrome_driver_url = Label(frame_group_header, text=URL_CHROME_DRIVER, fg="blue", cursor="hand2")
lbl_chrome_driver_url.grid(column=1, row=group_row_count, sticky = W)
lbl_chrome_driver_url.bind("<Button-1>", lambda e: open_url(URL_CHROME_DRIVER))
group_row_count +=1
lbl_firefox_driver = Label(frame_group_header, text=u'Firefox Driver')
lbl_firefox_driver.grid(column=0, row=group_row_count, sticky = E)
lbl_firefox_driver_url = Label(frame_group_header, text=URL_FIREFOX_DRIVER, fg="blue", cursor="hand2")
lbl_firefox_driver_url.grid(column=1, row=group_row_count, sticky = W)
lbl_firefox_driver_url.bind("<Button-1>", lambda e: open_url(URL_FIREFOX_DRIVER))
group_row_count +=1
lbl_edge_driver = Label(frame_group_header, text=u'Edge Driver')
lbl_edge_driver.grid(column=0, row=group_row_count, sticky = E)
lbl_edge_driver_url = Label(frame_group_header, text=URL_EDGE_DRIVER, fg="blue", cursor="hand2")
lbl_edge_driver_url.grid(column=1, row=group_row_count, sticky = W)
lbl_edge_driver_url.bind("<Button-1>", lambda e: open_url(URL_EDGE_DRIVER))
frame_group_header.grid(column=0, row=row_count)
def get_action_bar(root, language_code):
@ -1856,7 +1887,7 @@ def main():
load_GUI(root, config_dict)
GUI_SIZE_WIDTH = 460
GUI_SIZE_WIDTH = 500
GUI_SIZE_HEIGHT = 594
GUI_SIZE_MACOS = str(GUI_SIZE_WIDTH) + 'x' + str(GUI_SIZE_HEIGHT)