Selenium python set firefox profile

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium does not set firefox profile — python #6592

Selenium does not set firefox profile — python #6592

Comments

System
windows:10
Selenium:3.14
Python:3.7
Gecodriver:0.23

Expection:
Open the firefox with test profile

Issue:
Open the firefox with default profile
Create a temp profile folder to temp folder

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile from selenium import webdriver fp = FirefoxProfile("C:\\Users\\\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ji8rbij6.test") browser = webdriver.Firefox(firefox_profile=fp) 

The text was updated successfully, but these errors were encountered:

in this last example, options should be an instance of selenium.webdriver.firefox.options.Options() .. where are you creating it?

Sorry about code,i missed a line there.It is like this actually .

from selenium.webdriver.firefox.options import Options options=Options() options.add_argument("-profile") options.add_argument("C:/Users//AppData/Roaming/Mozilla/Firefox/Profiles/ji8rbij6.test") browser=webdriver.Firefox(options=options) 

1541767559696 mozrunner::runner INFO Running command: «C:\Users\AppData\Local\Mozilla Firefox\firefox.exe» «-marionette» «-profile» «C:\Users\AppData\Roaming\Mozilla\Firefox\Profiles\dnm8f0kz.default-1541758576709» «-foreground» «-no-remote» IPDL protocol error: Handler returned error code!

. [Parent][DispatchAsyncMessage] Error: PLayerTransaction::Msg_ReleaseLayer Processing error: message was
deserialized, but the handler returned false (indicating failure)

IPDL protocol error: Handler returned error code!

. [Parent][DispatchAsyncMessage] Error: PLayerTransaction::Msg_ReleaseLayer Processing error: message was
deserialized, but the handler returned false (indicating failure)

[Parent 10284, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346 [Parent 10284, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346 [Child 12268, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346[ Child 3464, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346 [Child 3464, C[Parent 10284, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346 [Child 12132, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346 [Child 1213

. [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
1541767610497 mozrunner::runner INFO Running command: «C:\Users\AppData\Local\Mozilla Firefox\firefox.exe» «-marionette» «-profile» «C:\Users\AppData\Roaming\Mozilla\Firefox\Profiles\dnm8f0kz.default-1541758576709» «-foreground» «-no-remote»

Источник

Читайте также:  Красивый серый цвет css

How to use the selenium.webdriver.FirefoxProfile function in selenium

To help you get started, we’ve selected a few selenium examples, based on popular ways it is used in public projects.

Secure your code as it’s written. Use Snyk Code to scan source code in minutes — no build needed — and fix issues immediately.

def __init__(self,showbrowser): display = Display(visible=0, size=(1600, 1024)) display.start() if not showbrowser: os.environ['MOZ_HEADLESS'] = '1' firefoxprofile = webdriver.FirefoxProfile() firefoxprofile.set_preference("permissions.default.desktop-notification", 1) firefoxprofile.set_preference("dom.webnotifications.enabled", 1) firefoxprofile.set_preference("dom.push.enabled", 1) self.driver = webdriver.Firefox(firefox_profile=firefoxprofile) self.driver.implicitly_wait(15) self.driver.delete_all_cookies()
from selenium import webdriver from selenium.webdriver.firefox.options import Options import requests import random import re page_url = "http://dev.kdlapi.com/testproxy" # 要访问的目标网页 # API接口,返回格式为json api_url = "" # API接口返回的ip proxy = requests.get(api_url).json()['data']['proxy_list'] ip, port = random.choice(proxy).split(":") port = int(port) profile = webdriver.FirefoxProfile() # 不使用代理的协议,注释掉对应的选项即可 settings = < 'network.proxy.type': 1, # 0: 不使用代理;1: 手动配置代理 'network.proxy.http': ip, 'network.proxy.http_port': port, 'network.proxy.ssl': ip, # 如果是https, 需要开启 'network.proxy.ssl_port': port, 'network.proxy.socks': ip, 'network.proxy.socks_port': port, # 'network.proxy.ftp': ip, # 'network.proxy.ftp_port': port > for key, value in settings.items(): profile.set_preference(key, value) profile.update_preferences()
# Loop through the four different configurations. for browser in ['chrome', 'firefox']: for mode in ['headless', 'graphical']: # Set up the driver with the appropriate settings. if browser == 'chrome': options = webdriver.ChromeOptions() if mode == 'headless': options.add_argument('headless') options.add_argument(f'load-extension= ') driver = webdriver.Chrome(chrome_options=options) elif browser == 'firefox': if mode == 'headless': os.environ['MOZ_HEADLESS'] = '1' elif mode == 'graphical': os.environ.pop('MOZ_HEADLESS', None) profile = webdriver.FirefoxProfile() profile.add_extension(extension_directory) driver = webdriver.Firefox(profile, firefox_binary=firefox_binary) # Navigate to the test page and let the extension do its thing. driver.get('https://intoli.com/blog/javascript-injection/test-page.html') # Save the results as an image. os.makedirs('img', exist_ok=True) filename = os.path.join('img', f'selenium-custom-web-extension- - -results.png') driver.get_screenshot_as_file(filename) print(f'Saved " ".') # Cleanup the driver before the next test. driver.quit()
for file in os.listdir(binarys_path): for br in browsers_names: if br in file: browsers_paths[br] = binarys_path + file if browser not in browsers_paths.keys(): print('[###] No option for this browser [###]\n') print('Your current options are: \n') for b in browsers_paths.keys(): print('- ' + b) print("\nIf you dont have any of them sorry for you =)..\n") sys.exit(1) if 'firefox' in browser: if f['proxy']: profile = webdriver.FirefoxProfile() profile.set_preference("network.proxy.type", 1) profile.set_preference("network.proxy.socks", f['proxy'].split(':')[0]) profile.set_preference("network.proxy.socks_port", int(f['proxy'].split(':')[1])) profile.update_preferences() try: driver = webdriver.Firefox(firefox_profile=profile) driver.wait = WebDriverWait(driver, 90) return driver except Exception as e: print('[#] Error while executing geckodriver') print('[#] Install geckodriver or upgrade it!') print(str(e)) else: try:
""" Configures and launches Firefox to run the vectorizer with. Sets headless mode, sets the download directory to the desired output directory, turns off page caching, and installs FathomFox and Fathom Trainees. We return the webdriver object, and the process IDs for both the Firefox process and the geckodriver process so we can shutdown either gracefully or ungracefully. """ print('Configuring Firefox. ', end='', flush=True) options = webdriver.FirefoxOptions() options.headless = not show_browser profile = webdriver.FirefoxProfile() profile.set_preference('browser.download.folderList', 2) profile.set_preference('browser.download.dir', str(pathlib.Path(output_directory).absolute())) profile.set_preference('browser.cache.disk.enable', False) profile.set_preference('browser.cache.memory.enable', False) profile.set_preference('browser.cache.offline.enable', False) firefox = webdriver.Firefox( options=options, firefox_profile=profile, service_log_path=f' /geckodriver.log', ) firefox.install_addon(fathom_fox, temporary=True) firefox.install_addon(fathom_trainees, temporary=True) print('Done') return firefox, firefox.capabilities['moz:processID'], firefox.service.process.pid
try: # Get new browser instance and put it into browser array. One browser for one thread. if browserString == '*chrome': chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument('--start-maximized') chromeOptions.add_argument('--log-path=' + self.workDir + '/browser_drivers/chromedriver.log') os.chdir(self.workDir + '/browser_drivers') self.browsers.append(webdriver.Chrome(executable_path=self.workDir + '/browser_drivers/chromedriver.exe', chrome_options=chromeOptions)) os.chdir(self.workDir) elif browserString == '*ie': self.browsers.append(webdriver.Ie(executable_path=self.workDir + '/browser_drivers/IEDriverServer.exe', log_file=self.workDir + '/browser_drivers/iedriver.log')) self.browsers[len(self.browsers) - 1].maximize_window() else: ffp = webdriver.FirefoxProfile(ffProfile) self.browsers.append(webdriver.Firefox(firefox_profile=ffp, timeout=opTimeout)) self.browsers[len(self.browsers) - 1].maximize_window() except BaseException: traceback.print_exc() return 1 return 0
def webdriver_firefox(): try: f = open(os.environ['HOME'] + os.sep + '.selenium_port', 'r') port = f.read() f.close() driver = webdriver.Remote(command_executor='http://127.0.0.1:%s/hub' % port, desired_capabilities=DesiredCapabilities.FIREFOX) except: default_profile = filter(lambda s: s.find('.selenium') >= 0, os.listdir(firefox_profiles_path))[0] profile = webdriver.FirefoxProfile(firefox_profiles_path + os.sep + default_profile) driver = webdriver.Firefox(profile) f = open(os.environ['HOME'] + os.sep + '.selenium_port', 'w') f.write(str(profile.port)) f.close() return driver
# set Firefox Agent to mobile agent user_agent = ( "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 " "(KHTML, like Gecko) FxiOS/18.1 Mobile/16B92 Safari/605.1.15" ) # keep user_agent Settings.user_agent = user_agent firefox_options = Firefox_Options() if headless_browser: firefox_options.add_argument("-headless") if browser_profile_path is not None: firefox_profile = webdriver.FirefoxProfile(browser_profile_path) else: firefox_profile = webdriver.FirefoxProfile() # set English language firefox_profile.set_preference("intl.accept_languages", "en-US") firefox_profile.set_preference("general.useragent.override", user_agent) if disable_image_load: # permissions.default.image = 2: Disable images load, # this setting can improve pageload & save bandwidth firefox_profile.set_preference("permissions.default.image", 2) if proxy_address and proxy_port: firefox_profile.set_preference("network.proxy.type", 1) firefox_profile.set_preference("network.proxy.http", proxy_address) firefox_profile.set_preference("network.proxy.http_port", int(proxy_port))
try: # Get new browser instance and put it into browser array. One browser for one thread. if browserString == '*chrome': chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument('--start-maximized') chromeOptions.add_argument('--log-path=' + workDir + '/browser_drivers/chromedriver.log') os.chdir(workDir + '/browser_drivers') browsers.append(webdriver.Chrome(executable_path=workDir + '/browser_drivers/chromedriver.exe', chrome_options=chromeOptions)) os.chdir(workDir) elif browserString == '*ie': browsers.append(webdriver.Ie(executable_path=workDir + '/browser_drivers/IEDriverServer.exe', log_file=workDir + '/browser_drivers/iedriver.log')) browsers[len(browsers) - 1].maximize_window() else: ffp = webdriver.FirefoxProfile(ffProfile) browsers.append(webdriver.Firefox(firefox_profile=ffp, timeout=opTimeout)) browsers[len(browsers) - 1].maximize_window() except BaseException: traceback.print_exc() return 1 return 0

Источник

Оцените статью