Python selenium.webdriver.chrome.options.Options() Examples
The following are 30
code examples of selenium.webdriver.chrome.options.Options().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
selenium.webdriver.chrome.options
, or try the search function
.
Example #1
Source File: xuexi.py From autoxuexi with GNU General Public License v3.0 | 8 votes |
def __init__(self, use_Dingtalk=False): chrome_options = Options() self.__exit_flag = threading.Event() self.__exit_flag.clear() self.use_Dingtalk = use_Dingtalk if config['mute']: chrome_options.add_argument('--mute-audio') # 关闭声音 if os.path.exists('driver/chrome.exe'): chrome_options.binary_location = 'driver/chrome.exe' # chrome_options.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错 # chrome_options.add_argument('window-size=800x600') #指定浏览器分辨率 # chrome_options.add_argument('--disable-gpu') #谷歌文档提到需要加上这个属性来规避bug # chrome_options.add_argument('--hide-scrollbars') #隐藏滚动条, 应对一些特殊页面 # chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度 if config['background_process'] and self.use_Dingtalk: chrome_options.add_argument('--headless') # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败 self.driver = webdriver.Chrome('driver/chromedriver.exe', options=chrome_options) LOGGER.setLevel(logging.CRITICAL)
Example #2
Source File: base.py From syncPlaylist with MIT License | 8 votes |
def __init__(self): self.browse = None self.source_playlist = None self.target_playlist_tag = None self.success_list = list() self.failed_list = list() os.environ["webdriver.chrome.driver"] = chrome_driver_path os.environ["webdriver.phantomjs.driver"] = phantomjs_driver_path # chromedriver = chrome_driver_path phantomjs_driver = phantomjs_driver_path opts = Options() opts.add_argument("user-agent={}".format(headers["User-Agent"])) # browser = webdriver.Chrome(chromedriver) browser = webdriver.PhantomJS(phantomjs_driver) self.browser = browser self.wait = ui.WebDriverWait(self.browser, 5) self.config = Config()
Example #3
Source File: autobrowser.py From code-jam-5 with MIT License | 6 votes |
def make_driver(headless: bool = True) -> webdriver: """ Creates a selenium driver interface for Chrome. You need to install the chromedriver provided by Google and make it accessible through PATH to be able to use it. """ opt = Options() if headless: opt.add_argument('--headless') opt.add_argument('lang=en') driver = webdriver.Chrome(__folder__ / 'chromedriver', chrome_options=opt) driver.set_window_size(1920, 1080) return driver
Example #4
Source File: conftest.py From idom with MIT License | 6 votes |
def create_driver(pytestconfig: Config, fresh_client: None, driver_timeout: float): """A Selenium web driver""" created_drivers = [] def create(): chrome_options = Options() if pytestconfig.option.headless: chrome_options.headless = True driver = Chrome(options=chrome_options) driver.set_window_size(1080, 800) driver.set_page_load_timeout(driver_timeout) driver.implicitly_wait(driver_timeout) created_drivers.append(driver) return driver yield create for d in created_drivers: d.quit()
Example #5
Source File: crawler.py From FutureNews with MIT License | 6 votes |
def get_driver(): current_platform = platform.system() driver = None if current_platform == 'Darwin': from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') driver = webdriver.Chrome('/Users/nolan/Documents/chromedriver', chrome_options=chrome_options) driver.set_page_load_timeout(60) time.sleep(0.5) if current_platform == 'Linux': from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') driver = webdriver.Chrome(chrome_options=chrome_options) driver.set_page_load_timeout(60) time.sleep(0.5) return driver
Example #6
Source File: test_frontend.py From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License | 6 votes |
def setUpClass(cls): super(LiveLocationTest, cls).setUpClass() driver_path = os.path.join(settings.BASE_DIR, "drivers", "chromedriver") chrome_options = Options() if not SHOW_BROWSER: chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=1200,800") cls.browser = webdriver.Chrome( executable_path=driver_path, options=chrome_options ) cls.browser.delete_all_cookies() image_path = cls.save_test_image("test.jpg") cls.location = Location.objects.create( name="Park Güell", description="If you want to see something spectacular, come to Barcelona, Catalonia, Spain and visit Park Güell. Located on a hill, Park Güell is a public park with beautiful gardens and organic architectural elements.", picture=image_path, # dummy path ) cls.username = "admin" cls.password = "admin" cls.superuser = User.objects.create_superuser( username=cls.username, password=cls.password, email="admin@example.com" )
Example #7
Source File: infra.py From awe with MIT License | 6 votes |
def driver(): options = Options() options.headless = True arguments = ['--incognito', '--private'] if platform.system() == 'Darwin': chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' data_dir = os.path.join(tempfile.gettempdir(), 'local-probe-chrome-data') options.binary_location = chrome_path else: arguments.extend(['--no-sandbox', '--disable-dev-shm-usage']) data_dir = '/home/circleci/project/data' arguments.append('--user-data-dir={}'.format(data_dir)) for argument in arguments: options.add_argument(argument) result = webdriver.Chrome(options=options) result.set_window_size(1600, 1000) yield result result.close()
Example #8
Source File: export_examples.py From awe with MIT License | 6 votes |
def _driver(): options = Options() options.headless = True arguments = ['--incognito', '--private'] chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' data_dir = os.path.join(tempfile.gettempdir(), 'local-probe-chrome-data') options.binary_location = chrome_path arguments.append('--user-data-dir={}'.format(data_dir)) for argument in arguments: options.add_argument(argument) result = webdriver.Chrome(options=options) try: result.set_window_size(1600, 1000) yield result finally: result.close()
Example #9
Source File: Chrome.py From jarvis with MIT License | 6 votes |
def get_driver(self): cur_path_list = os.getcwd().split("/")[:-1] cur_path = "/".join(cur_path_list) + "/dependencies/chromedriver/chromedriver" if not os.path.exists(cur_path): self.dl_driver_mac() cur_path_list = os.getcwd().split("/")[:-1] cur_path = "/".join(cur_path_list) + "/config/" cmd = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-' \ 'dir="{}" '.format(cur_path) subprocess.Popen(cmd, shell=True) chrome_options = Options() chrome_options.debugger_address = "127.0.0.1:9222" cur_path_list = os.getcwd().split("/")[:-1] cur_path = "/".join(cur_path_list) + "/dependencies/chromedriver/chromedriver" driver = webdriver.Chrome(cur_path, options=chrome_options) cmd = """ osascript -e 'tell application "System Events" to keystroke "h" using {command down}' """ os.system(cmd) return driver
Example #10
Source File: get-tagged-photos.py From facebook-photos-download with MIT License | 6 votes |
def start_session(username, password): print("Opening Browser...") wd_options = Options() wd_options.add_argument("--disable-notifications") wd_options.add_argument("--disable-infobars") wd_options.add_argument("--mute-audio") wd_options.add_argument("--start-maximized") driver = webdriver.Chrome(chrome_options=wd_options) #Login driver.get("https://www.facebook.com/") print("Logging In...") email_id = driver.find_element_by_id("email") pass_id = driver.find_element_by_id("pass") email_id.send_keys(username) pass_id.send_keys(password) driver.find_element_by_id("loginbutton").click() return driver
Example #11
Source File: test_frontend.py From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License | 6 votes |
def setUpClass(cls): super(LiveLocationTest, cls).setUpClass() driver_path = os.path.join(settings.BASE_DIR, "drivers", "chromedriver") chrome_options = Options() if not SHOW_BROWSER: chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=1200,800") cls.browser = webdriver.Chrome( executable_path=driver_path, options=chrome_options ) cls.browser.delete_all_cookies() image_path = cls.save_test_image("test.jpg") cls.location = Location.objects.create( name="Park Güell", description="If you want to see something spectacular, come to Barcelona, Catalonia, Spain and visit Park Güell. Located on a hill, Park Güell is a public park with beautiful gardens and organic architectural elements.", picture=image_path, # dummy path ) cls.username = "admin" cls.password = "admin" cls.superuser = User.objects.create_superuser( username=cls.username, password=cls.password, email="admin@example.com" )
Example #12
Source File: cap_train.py From chainerui with MIT License | 6 votes |
def chrome_driver(): chrome_driver_path = cb.utils.get_chromedriver_path() chrome_driver_exe = os.path.join( chrome_driver_path, cb.utils.get_chromedriver_filename()) if os.name != 'nt' and 'microsoft' in platform.uname().version.lower(): chrome_driver_exe += '.exe' if not os.path.exists(chrome_driver_exe): msg = 'invalid driver module at \'{}\' error'.format(chrome_driver_exe) raise ValueError(msg) options = Options() options.add_argument('--headless') options.add_argument('--window-size=1200,1024') driver = webdriver.Chrome( chrome_options=options, executable_path=chrome_driver_exe) try: yield driver finally: driver.quit()
Example #13
Source File: shutterscrape.py From shutterscrape with MIT License | 6 votes |
def imagescrape(): try: chrome_options = Options() chrome_options.add_argument("--no-sandbox") driver = webdriver.Chrome(chrome_options=chrome_options) driver.maximize_window() for i in range(1, searchPage + 1): url = "https://www.shutterstock.com/search?searchterm=" + searchTerm + "&sort=popular&image_type=" + image_type + "&search_source=base_landing_page&language=en&page=" + str(i) driver.get(url) data = driver.execute_script("return document.documentElement.outerHTML") print("Page " + str(i)) scraper = BeautifulSoup(data, "lxml") img_container = scraper.find_all("img", {"class":"z_h_c z_h_e"}) for j in range(0, len(img_container)-1): img_src = img_container[j].get("src") name = img_src.rsplit("/", 1)[-1] try: urlretrieve(img_src, os.path.join(scrape_directory, os.path.basename(img_src))) print("Scraped " + name) except Exception as e: print(e) driver.close() except Exception as e: print(e)
Example #14
Source File: lazyshot.py From lazyshot with MIT License | 6 votes |
def takeScreeshot(url): if len(url) == 0: return False else: u = urlParser(url.strip()) if u: if not os.path.exists(OUTPUT): os.makedirs(OUTPUT) chrome_options = Options() chrome_options.add_argument("--headless") driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options) driver.set_window_size(1280, 1024) driver.get(u) driver.save_screenshot(os.getcwd() + '/' +OUTPUT + '/screenshot-' + urlparse(url).path + '.png') return True else: return False
Example #15
Source File: test_chat_behavior.py From chatter with MIT License | 6 votes |
def setUp(self): set_up_data() # To run Chrome in CI environments. chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument("window-size=1200x600") if (os.environ.get('SELENIUM_VISUAL', None) == '1'): self.browser = webdriver.Chrome() self.browser.set_window_size(1600, 900) else: self.browser = webdriver.Chrome(options = chrome_options) self.domain_home = 'http://localhost' + ':' + \ self.live_server_url.split(':')[-1]
Example #16
Source File: whatsapp.py From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 | 6 votes |
def __init__(self, wait, screenshot=None, session=None): chrome_options = Options() if session: chrome_options.add_argument("--user-data-dir={}".format(session)) self.browser = webdriver.Chrome(options=chrome_options) # we are using chrome as our webbrowser else: self.browser = webdriver.Chrome() self.browser.get("https://web.whatsapp.com/") # emoji.json is a json file which contains all the emojis with open("emoji.json") as emojies: self.emoji = json.load(emojies) # This will load the emojies present in the json file into the dict WebDriverWait(self.browser,wait).until(EC.presence_of_element_located( (By.CSS_SELECTOR, '._3FRCZ'))) if screenshot is not None: self.browser.save_screenshot(screenshot) # This will save the screenshot to the specified file location # This method is used to send the message to the individual person or a group # will return true if the message has been sent, false else
Example #17
Source File: crawler_selenium.py From Price-monitor with GNU General Public License v3.0 | 6 votes |
def __init__(self, proxy=None): chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument('--ignore-ssl-errors') prefs = {"profile.managed_default_content_settings.images": 2} chrome_options.add_experimental_option("prefs", prefs) if proxy: proxy_address = proxy['https'] chrome_options.add_argument('--proxy-server=%s' % proxy_address) logging.info('Chrome using proxy: %s', proxy['https']) # 设置等待策略为不等待完全加载 caps = DesiredCapabilities().CHROME caps["pageLoadStrategy"] = "none" self.chrome = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=caps) # jd sometimes load google pic takes much time self.chrome.set_page_load_timeout(30) # set timeout for script self.chrome.set_script_timeout(30)
Example #18
Source File: test_frontend.py From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License | 6 votes |
def setUpClass(cls): super(LiveLocationTest, cls).setUpClass() driver_path = os.path.join(settings.BASE_DIR, "drivers", "chromedriver") chrome_options = Options() if not SHOW_BROWSER: chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=1200,800") cls.browser = webdriver.Chrome( executable_path=driver_path, options=chrome_options ) cls.browser.delete_all_cookies() image_path = cls.save_test_image("test.jpg") cls.location = Location.objects.create( name="Park Güell", description="If you want to see something spectacular, come to Barcelona, Catalonia, Spain and visit Park Güell. Located on a hill, Park Güell is a public park with beautiful gardens and organic architectural elements.", picture=image_path, # dummy path ) cls.username = "admin" cls.password = "admin" cls.superuser = User.objects.create_superuser( username=cls.username, password=cls.password, email="admin@example.com" )
Example #19
Source File: session.py From wencai with MIT License | 6 votes |
def get_driver(self, url, execute_path=None, is_headless=True): driver = None try: chrome_options = Options() if is_headless: chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') if execute_path is None: driver = webdriver.Chrome(chrome_options=chrome_options) else: driver = webdriver.Chrome(executable_path=execute_path, chrome_options=chrome_options) driver.get(url) return driver.page_source except Exception as e: raise IOError(e) finally: if driver is not None: driver.quit()
Example #20
Source File: cookies.py From wencai with MIT License | 6 votes |
def getHeXinVByHttp(self, source): driver = None try: chrome_options = Options() if self.is_headless: chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') if self.execute_path is None: driver = webdriver.Chrome(chrome_options=chrome_options) else: driver = webdriver.Chrome(executable_path=self.execute_path, chrome_options=chrome_options) driver.get(WENCAI_LOGIN_URL[source]) time.sleep(5) cookies = driver.get_cookies() v = '' for i in cookies: if 'name' in i.keys(): if i['name'] == 'v': v = i['value'] return v except Exception as e: print(e) finally: if driver is not None: driver.quit()
Example #21
Source File: IntegrationTests.py From dash-bio with MIT License | 6 votes |
def setUpClass(cls): super(IntegrationTests, cls).setUpClass() options = Options() if 'DASH_TEST_CHROMEPATH' in os.environ: options.binary_location = os.environ['DASH_TEST_CHROMEPATH'] cls.driver = webdriver.Chrome(chrome_options=options) root_static_dir = os.path.abspath( os.path.join( os.path.dirname(__file__), '..', 'assets' ) ) if os.environ.get('PERCY_ENABLED', False): loader = percy.ResourceLoader( webdriver=cls.driver, base_url='/assets', root_dir=root_static_dir ) cls.percy_runner = percy.Runner(loader=loader) cls.percy_runner.initialize_build()
Example #22
Source File: test_frontend.py From callisto-core with GNU Affero General Public License v3.0 | 5 votes |
def setup_browser(cls): chrome_options = Options() # deactivate with `HEADED=TRUE pytest...` if headless_mode(): chrome_options.add_argument("--headless") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") cls.browser = webdriver.Chrome(chrome_options=chrome_options)
Example #23
Source File: test_e2e_menu.py From django-baton with MIT License | 5 votes |
def setUp(self): chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-extensions') chrome_options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Chrome( ChromeDriverManager().install(), options=chrome_options, ) self.driver.set_window_size(1920, 1080) self.driver.implicitly_wait(10) self.login()
Example #24
Source File: test_e2e_index.py From django-baton with MIT License | 5 votes |
def setUp(self): chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-extensions') chrome_options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Chrome( ChromeDriverManager().install(), options=chrome_options, ) self.driver.set_window_size(1920, 1080) self.driver.implicitly_wait(10) self.login()
Example #25
Source File: automation.py From pybitrix24 with MIT License | 5 votes |
def _provide_chrome_options(self): chrome_options = Options() chrome_options.add_experimental_option( "excludeSwitches", ["enable-logging"]) # disable logging if self.headless: chrome_options.add_argument('--headless') return chrome_options
Example #26
Source File: test_e2e_input_filter.py From django-baton with MIT License | 5 votes |
def setUp(self): chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-extensions') chrome_options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Chrome( ChromeDriverManager().install(), options=chrome_options, ) self.driver.set_window_size(1920, 1080) self.driver.implicitly_wait(10) self.login()
Example #27
Source File: stackoverflow.py From vexbot with GNU General Public License v3.0 | 5 votes |
def __init__(self, room='https://chat.stackoverflow.com/rooms/6/python'): options = Options() options.add_argument('--headless') self.driver = webdriver.Chrome(chrome_options=options) self.driver.get(room) self.messaging = Messaging('stack')
Example #28
Source File: test_e2e_index_mobile.py From django-baton with MIT License | 5 votes |
def setUp(self): chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-extensions') chrome_options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Chrome( ChromeDriverManager().install(), options=chrome_options, ) self.driver.set_window_size(480, 600) self.driver.implicitly_wait(10) self.login()
Example #29
Source File: conftest.py From pyodide with Mozilla Public License 2.0 | 5 votes |
def get_driver(self): from selenium.webdriver import Chrome from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import WebDriverException options = Options() options.add_argument("--headless") options.add_argument("--no-sandbox") self.JavascriptException = WebDriverException return Chrome(options=options)
Example #30
Source File: test_e2e_login.py From django-baton with MIT License | 5 votes |
def setUp(self): chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-extensions') chrome_options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Chrome( ChromeDriverManager().install(), options=chrome_options,)