python selenium im getting an multiple errors in my class? - python

I'm new to Python, and I'm trying to modify SeleniumLibrary from robotframwork to meet my own needs. Unfortunately,l I'm getting multiple errors and I don't know why.
There are multiple functions to call different browsers with binary path and headless option.
import os
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
DEFAULT_BROWSR = 'chrome'
DRIVERS_PATH = os.path.join( os.getcwd() , "\drivers\\" )
BROWSER_NAMES = {
'ff': "_make_ff",
'firefox': "_make_ff",
'headlessfirefox': '_make_headless_ff',
'gc': "_make_chrome",
'googlechrome': "_make_chrome",
'headlesschrome': '_make_headless_chrome',
'chrome': "_make_chrome",
}
BROWSER_PATHS = {
'_make_ff': "geckodriver-win32\geckodriver.exe",
'_make_headless_ff': "geckodriver-win32\geckodriver.exe",
'_make_chrome': "chromedriver_win32\chromedriver.exe",
'_make_headless_chrome': "chromedriver_win32\chromedriver.exe",
}
class driver(object):
"""docstring for driver"""
def __init__(self):
self.driver = None
self.driver_path = None
self.timeout = 20
self.implicit_wait = 5
def create(self,browser_name=DEFAULT_BROWSR):
return self._make_driver(browser_name)
def _make_driver(self, browser_name, desired_capabilities=None, profile_dir=None, remote=None):
creation_func = self._get_driver_creation_function(browser_name)
driver_path = self._get_driver_path(browser_name)
desired_capabilities = {"chrome.binary": driver_path,}
driver = creation_func(remote, desired_capabilities, profile_dir)
driver.set_script_timeout(self.timeout)
driver.implicitly_wait(self.implicit_wait)
return driver
""" Return browser function name """
def _get_driver_creation_function(self,browser_name):
try:
func_name = BROWSER_NAMES[browser_name]
except KeyError:
raise ValueError(browser_name + " is not a supported browser.")
return getattr(self, func_name)
""" Return browser driver path """
def _get_driver_path(self,browser_name):
try:
func_name = self._get_driver_creation_function(browser_name)
driver_path = os.path.join(DRIVERS_PATH , BROWSER_PATHS[func_name])
except KeyError:
raise ValueError(browser_name + " is not a supported browser.")
return getattr(self, driver_path)
""" Used inside driver creation functions """
def _generic_make_driver(self, webdriver_type, desired_cap_type, remote_url, desired_caps, options=None):
if is_falsy(remote_url):
if options is None:
driver = webdriver_type()
else:
driver = webdriver_type(options=options)
else:
driver = self._create_remote_web_driver(desired_cap_type, remote_url, desired_caps, options=options)
return driver
def _create_remote_web_driver(self, capabilities_type, remote_url, desired_capabilities=None, profile=None, options=None):
desired_capabilities_object = capabilities_type.copy()
if not isinstance(desired_capabilities, dict):
desired_capabilities = self._parse_capabilities_string(desired_capabilities)
desired_capabilities_object.update(desired_capabilities or {})
return webdriver.Remote(desired_capabilities=desired_capabilities_object,
command_executor=str(remote_url), browser_profile=profile,
options=options)
def _make_ff(self, remote, desired_capabilities, profile_dir, options=None):
if is_falsy(profile_dir):
profile = webdriver.FirefoxProfile()
else:
profile = webdriver.FirefoxProfile(profile_dir)
if is_truthy(remote):
driver = self._create_remote_web_driver(webdriver.DesiredCapabilities.FIREFOX, remote,
desired_capabilities, profile, options=options)
else:
driver = webdriver.Firefox(firefox_profile=profile, options=options, **self._geckodriver_log_config)
return driver
def _make_headless_ff(self, remote, desired_capabilities, profile_dir):
options = webdriver.FirefoxOptions()
options.set_headless()
return self._make_ff(remote, desired_capabilities, profile_dir, options=options)
def _make_chrome(self, remote, desired_capabilities, profile_dir, options=None):
return self._generic_make_driver(
webdriver.Chrome, webdriver.DesiredCapabilities.CHROME, remote,
desired_capabilities, options=options)
def _make_headless_chrome(self, remote, desired_capabilities, profile_dir):
options = webdriver.ChromeOptions()
options.set_headless()
return self._make_chrome(remote, desired_capabilities, profile_dir, options)
This function should open a browser which will call the default chrome driver:
driver().create()

As highlighted in the comments, this kind of issues can be easily resolved by using a properly configured Python IDE with debugging capabilities. There are several good ones, both open source and commercial.
In this particular case your script has two problems:
Missing Import:
from robot.utils import is_falsy
Function that needs a bit of rewriting as the func_name needs to be a different value.
""" Return browser driver path """
def _get_driver_path(self,browser_name):
try:
#func_name = self._get_driver_creation_function(browser_name)
driver_path = os.path.join(DRIVERS_PATH , BROWSER_PATHS[BROWSER_NAMES[browser_name]])
except KeyError:
raise ValueError(browser_name + " is not a supported browser.")
return driver_path

Related

Firefox processes not ending when django tests which use selenium are done running, even after driver.quit()

Here's some relevant code:
class PpeLiveTest(LiveServerTestCase):
def test_algamoil_incentives_table_total(self):
options = webdriver.FirefoxOptions()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
driver.get('https://dev.redacted.com/pr-run-ppe?group=AL%2FGA%2FMO%2FIL&check_date=05%2F05%2F2022')
# login first
username_element = driver.find_element_by_id('id_login')
username_element.send_keys('mjohnson#doozer.com')
password_element = driver.find_element_by_id('id_password')
password_element.send_keys(os.environ.get('ADMIN_PASS'))
login_button = driver.find_element_by_xpath('/html/body/div/div/div/form/button')
login_button.click()
incentives_table = driver.find_elements_by_css_selector('#incentives-table > tbody')[0]
georgia_row = incentives_table.find_elements_by_css_selector('tr')[4]
georgia_total_cell = georgia_row.find_elements_by_css_selector('td')[2]
alabama_row = incentives_table.find_elements_by_css_selector('tr')[12]
alabama_total_cell = alabama_row.find_elements_by_css_selector('td')[2]
missouri_row = incentives_table.find_elements_by_css_selector('tr')[16]
missouri_total_cell = missouri_row.find_elements_by_css_selector('td')[2]
illinois_row = incentives_table.find_elements_by_css_selector('tr')[21]
illinois_total_cell = illinois_row.find_elements_by_css_selector('td')[2]
total_row = incentives_table.find_elements_by_css_selector('tr')[22]
total_cell = total_row.find_elements_by_css_selector('td')[2]
algamoil_sum = (
int(georgia_total_cell.text.replace(',', '')) +
int(alabama_total_cell.text.replace(',', '')) +
int(missouri_total_cell.text.replace(',','')) +
int(illinois_total_cell.text.replace(',',''))
)
total_cell_value = int(total_cell.text.replace(',',''))
driver.quit()
self.assertEqual(total_cell_value, algamoil_sum)
As you can see, driver.quit() is at the end of this test, but after each test (this is one of 6 like it), the firefox processes stay running. Why?
Any help is appreciated, thanks in advance.

'WebDriver' object has no attribute 'find_elemnt_by_name', Selenium unit test

I have tried to do some unit tests using Selenium guide:
https://selenium-python.readthedocs.io/page-objects.html
Also find this youtube tutorial but, this didn't help:
https://www.youtube.com/watch?v=O_sIPPA4euw
And suddenly, I'm stuck on error and I can't handle this. Error:
Urz╣dzenie do│╣czone do komputera nie dzia│a. <- Its says "Device conected to pc don't work"
DevTools listening on ws://127.0.0.1:59733/devtools/browser/b08ba32b-aab7-4000-a232-17ee5f8ee262
[2412:14716:0131/030125.624:ERROR:disk_cache.cc(185)] Unable to create cache
[15264:6784:0131/030127.670:ERROR:chrome_browser_main_extra_parts_metrics.cc(227)] START: ReportBluetoothAvailability(). If you don't see the END: message, this is crbug.com/1216328.
[15264:6784:0131/030127.671:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] END: ReportBluetoothAvailability()
[15264:6784:0131/030127.671:ERROR:chrome_browser_main_extra_parts_metrics.cc(235)] START: GetDefaultBrowser(). If you don't see the END: message, this is crbug.com/1216328.
[15264:10740:0131/030127.672:ERROR:device_event_log_impl.cc(214)] [03:01:27.672] USB: usb_device_handle_win.cc:1050 Failed to read descriptor from node connection: Urz╣dzenie do│╣czone
do komputera nie dzia│a. (0x1F)
[15264:10740:0131/030127.673:ERROR:device_event_log_impl.cc(214)] [03:01:27.673] USB: usb_device_handle_win.cc:1050 Failed to read descriptor from node connection: Urz╣dzenie do│╣czone
do komputera nie dzia│a. (0x1F)
[15264:6784:0131/030127.685:ERROR:chrome_browser_main_extra_parts_metrics.cc(239)] END: GetDefaultBrowser()
E
======================================================================
ERROR: test_login (__main__.LoginTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\thein\PycharmProjects\socialMeUp\main\tests\main.py", line 16, in test_login
login.search_username = "admin"
File "C:\Users\thein\PycharmProjects\socialMeUp\main\tests\element.py", line 7, in __set__
WebDriverWait(driver, 100).until(
File "C:\Users\thein\PycharmProjects\socialMeUp\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 78, in until
value = method(self._driver)
File "C:\Users\thein\PycharmProjects\socialMeUp\main\tests\element.py", line 8, in <lambda>
lambda d: driver.find_elemnt_by_name(self.locator))
AttributeError: 'WebDriver' object has no attribute 'find_elemnt_by_name'
Code:
main.py
import time
import unittest
from selenium import webdriver
import page
class LoginTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(r"E:\operadriver\chromedriver.exe")
self.driver.get('http://127.0.0.1:8000/')
def test_login(self):
login = page.LoginPage(self.driver)
time.sleep(3)
login.search_username = "admin"
login.search_password = "haslo"
time.sleep(3)
login.click_login()
time.sleep(3)
assert login.is_login()
def tearDown(self):
self.driver.close()
if __name__ == '__main__':
unittest.main()
page.py:
from locator import LoginPageLocator, MainPageLocator
from element import BasePageElement
class SearchUsername(BasePageElement):
locator = "username"
class SearchPassword(BasePageElement):
locator = "password"
class BasePage(object):
def __init__(self, driver):
self.driver = driver
class MainPage(BasePage):
def is_title_matches(self):
return "Python" in self.driver.title
def click_add_photo(self):
element = self.driver.find_element(*MainPageLocator.ADD_PHOTO)
element.click()
class LoginPage(BasePage):
search_username = SearchUsername()
search_password = SearchPassword()
def is_login(self):
return 'Profile' in self.driver.page_source
def click_login(self):
element = self.driver.find_element(*LoginPageLocator.SUBMIT_BUTTON)
element.click()
element.py
from selenium.webdriver.support.ui import WebDriverWait
class BasePageElement(object):
def __set__(self, obj, value):
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda d: driver.find_elemnt_by_name(self.locator))
driver.find_elemnt_by_name(self.locator).clear()
driver.find_elemnt_by_name(self.locator).send_keys(value)
def __get__(self, obj, owner):
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda d: driver.find_elemnt_by_name(self.locator))
element = driver.find_elemnt_by_name(self.locator)
return element.get_attribute("value")
locator.py
from selenium.webdriver.common.by import By
class MainPageLocator(object):
ADD_PHOTO = (By.NAME, 'addPhoto')
class LoginPageLocator(object):
SUBMIT_BUTTON = (By.NAME, 'submit_button')

Python Selenium Printing Save-As-PDF Waiting for Filename Input

I'm trying to save a website as PDF through printing dialog. My code allows me to save as pdf, but asks me to input a filename, which I don't know how to pass a filename to the pop up box.
Attached is my code:
import time
from selenium import webdriver
import os
class printing_browser(object):
def __init__(self):
self.profile = webdriver.FirefoxProfile()
self.profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False)
self.profile.set_preference("pdfjs.disabled", True)
self.profile.set_preference("print.always_print_silent", True)
self.profile.set_preference("print.show_print_progress", False)
self.profile.set_preference("browser.download.show_plugins_in_list",False)
foxdriver = r'C:\Users\AShen\Documents\Workspace\geckodriver.exe'
self.driver = webdriver.Firefox(executable_path=foxdriver,firefox_profile = self.profile)
time.sleep(5)
def get_page_and_print(self, page):
self.driver.get(page)
time.sleep(5)
self.driver.execute_script("window.print();")
if __name__ == "__main__":
browser_that_prints = printing_browser()
browser_that_prints.get_page_and_print('http://www.google.com/')
These days I had the same question.
I solved it without using the pyautogui in these case, because I use different PCs and monitors and I didn't want to depend on the position of the click.
I was able to solve it using the about:config... changing them with each necessary print (in PDF).
The name of my printer "in PDF" in Ubuntu is "Print to File" (defined in print_printer) and the settings of about:config need to be this printer...
For example: print.printer_Print_to_File.print_to_file: true
import os
import time
from selenium import webdriver
class printing_browser(object):
def __init__(self):
self.profile = webdriver.FirefoxProfile()
self.profile.set_preference('services.sync.prefs.sync.browser.download.manager.showWhenStarting', False)
self.profile.set_preference('pdfjs.disabled', True)
self.profile.set_preference('print.always_print_silent', True)
self.profile.set_preference('print.show_print_progress', False)
self.profile.set_preference('browser.download.show_plugins_in_list', False)
self.profile.set_preference('browser.download.folderList', 2)
self.profile.set_preference('browser.download.dir', '')
self.profile.set_preference('browser.download.manager.showWhenStarting', False)
self.profile.set_preference('browser.aboutConfig.showWarning', False)
self.profile.set_preference('print.print_headerright', '')
self.profile.set_preference('print.print_headercenter', '')
self.profile.set_preference('print.print_headerleft', '')
self.profile.set_preference('print.print_footerright', '')
self.profile.set_preference('print.print_footercenter', '')
self.profile.set_preference('print.print_footerleft', '')
self.profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream;application/vnd.ms-excel;text/html')
foxdriver = r'C:\Users\AShen\Documents\Workspace\geckodriver.exe'
self.driver = webdriver.Firefox(
executable_path=foxdriver,
firefox_profile=self.profile
)
time.sleep(1)
def get_page_and_print(self, page, filepath):
# Get about:config
self.driver.get('about:config')
time.sleep(1)
# Define Configurations
script = """
var prefs = Components.classes['#mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref('print.always_print_silent', true);
prefs.setCharPref('print_printer', 'Print to File');
prefs.setBoolPref('print.printer_Print_to_File.print_to_file', true);
prefs.setCharPref('print.printer_Print_to_File.print_to_filename', '{}');
prefs.setBoolPref('print.printer_Print_to_File.show_print_progress', true);
""".format(filepath)
# Set Configurations
self.driver.execute_script(script)
time.sleep(1)
# Get site to print in pdf
self.driver.get(page)
time.sleep(2)
self.driver.execute_script("window.print();")
browser_that_prints = printing_browser()
browser_that_prints.get_page_and_print('http://www.google.com', os.path.join(os.getcwd(), 'mywebpage.pdf'))
Oh, it is very easy if you know about pyautogui.
This is an amazing module that allows you to automate your curser.
So essentially, you need to figure out the place where the popup appears and use pyautogui to click it for you.
All you need to add is:
time.sleep(3)
i=random.randint(0,1000)
file_name=('name_pdf '+str(i))
print (file_name)
pyautogui.typewrite(file_name)
pyautogui.click(512,449)
Entire code structure will look like this:
import time
import pyautogui
from selenium import webdriver
import os
class printing_browser(object):
def __init__(self):
self.profile = webdriver.FirefoxProfile()
self.profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False)
self.profile.set_preference("pdfjs.disabled", True)
self.profile.set_preference("print.always_print_silent", True)
self.profile.set_preference("print.show_print_progress", False)
self.profile.set_preference("browser.download.show_plugins_in_list",False)
foxdriver = r'C:\Users\Pranjal Pathak\Desktop\Titanic Kaggle\geckodriver.exe'
self.driver = webdriver.Firefox(executable_path=foxdriver,firefox_profile = self.profile)
time.sleep(5)
def get_page_and_print(self, page):
self.driver.get(page)
time.sleep(5)
self.driver.execute_script("window.print();")
if __name__ == "__main__":
browser_that_prints = printing_browser()
browser_that_prints.get_page_and_print('http://www.python.org/')
time.sleep(3)
i=random.randint(0,1000)
file_name=('name_pdf '+str(i))
print (file_name)
pyautogui.typewrite(file_name)
pyautogui.click(512,449)
Note: 1. I have selected the name of the file as name+any random integer between 1 to 1000 to change name every time you save the file. This way it will save every time you run the code as the names will be different every time.
If this types the name but does not save the file, you might want to change the coordinates of your curser. Let me know if that happens.

Not able to find locator in appium python

I am new to appium python client and need your suggestions to solve my below issue.PFA uiautomator viewer screen shot.Not sure if this is the reason: after typing into email field, a keyboard opens up so password and sign in button are not located
I have downloaded a free sample xxx.apk and created below script to test it:
class CareZoneAndroidTests(unittest.TestCase):
"Class to run tests against the Care Zone app"
def setUp(self):
"Setup for the test"
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.2'
desired_caps['deviceName'] = 'Android Emulator'
# Returns abs path relative to this file and not cwd
desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'D:/Programs/myapp/CareZone_v6.6.0.0 (flagship)_apkpure.com.apk'))
desired_caps['appPackage'] = 'com.carezone.caredroid.careapp.medications'
desired_caps['appActivity'] = 'com.carezone.caredroid.careapp.ui.activity.LandingActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
"Tear down the test"
self.driver.quit()
def test_login(self):
"Test the Login Page launches correctly"
self.driver.implicitly_wait(120)
print "After WAIT----------------->>>>>>>"
#Click on Sign in button
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_toolbar_action")
self.driver.implicitly_wait(15)
element.click()
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_mail_edit")
self.driver.implicitly_wait(10)
element.click()
element.send_keys("abc#ini.com");
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_password_edit")
element.click()
element.send_keys("abc");
self.driver.implicitly_wait(10)
#element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_bton")
#element = self.driver.find_element_by_accessibility_id('Sign In')
element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")')
element.click()
Issue:
test_login (main.CareZoneAndroidTests) Test the Login Page
launches correctly ... After WAIT----------------->>>>>>> ERROR
====================================================================== ERROR: test_login (main.CareZoneAndroidTests) Test the Login Page
launches correctly
---------------------------------------------------------------------- Traceback (most recent call last): File
"D:\Programs\myapp\CareZoneTests.py", line 42, in test_login
element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")') File
"D:\Programs\Python275\lib\site-packages\appium\webdriver\webdriver.py",
line 133, in find_element_by_android_uiautomator
return self.find_element(by=By.ANDROID_UIAUTOMATOR, value=uia_string) File
"D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 752, in find_element
'value': value})['value'] File "D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 236, in execute
self.error_handler.check_response(response) File "D:\Programs\Python275\lib\site-packages\appium\webdriver\errorhandler.py",
line 29, in check_response
raise wde NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
Tried below but all are failing for the same reason:
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_bton")
element = self.driver.find_element_by_accessibility_id('Sign In')
element = self.driver.find_element_by_android_uiautomator('new
UiSelector().text("Sign In")')
Try to find element by ID :
element = self.driver.find_element_by_id('Sign In')
updated :
Try to put hidekeyboard(); before doing the action of selection an element in order to hide your keyboard !
Below code worked fine for me:
class CareZoneAndroidTests(unittest.TestCase):
"Class to run tests against the Care Zone app"
def setUp(self):
"Setup for the test"
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.2'
desired_caps['deviceName'] = 'Android Emulator'
# Returns abs path relative to this file and not cwd
desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'D:/Programs/myapp/CareZone_v6.6.0.0 (flagship)_apkpure.com.apk'))
desired_caps['appPackage'] = 'com.carezone.caredroid.careapp.medications'
desired_caps['appActivity'] = 'com.carezone.caredroid.careapp.ui.activity.LandingActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
"Tear down the test"
self.driver.quit()
def test_login(self):
"Test the Login Page launches correctly"
self.driver.implicitly_wait(120)
print "Sign in Page"
element = self.driver.find_element_by_xpath("//android.widget.TextView[#text='Have an account? Sign In']")
self.driver.implicitly_wait(15)
element.click()
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_mail_edit")
element.click()
element.send_keys("ja.i#c.com");
self.driver.implicitly_wait(3)
self.driver.keyevent(61)
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_password_edit")
element.click()
element.send_keys("ni");
self.driver.implicitly_wait(3)
print "Click TABS 2 times to get Sign In button-->>>>>>>"
self.driver.keyevent(61)
self.driver.keyevent(61)
element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_bton")
element.click()
self.driver.implicitly_wait(120)
print "TEST OK"

Selenium Chromedriver download profile

i usually use the following function to set profile for Firefox
def FirefoxProfile(path, handlers):
debug = True
if debug: print "%r - %s(%r, %r)" % (time.asctime(), "FirefoxProfile", path, handlers)
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.manager.showWhenStarting",False)
if (not(isfile(path)) & exists(path)):
profile.set_preference("browser.download.folderList",2)
profile.set_preference("browser.download.dir", path)
profile.set_preference("browser.download.downloadDir", path)
profile.set_preference("browser.download.defaultFolder", path)
else:
profile.set_preference("browser.download.folderList",1)
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", handlers)
profile.set_preference("pdfjs.disabled", True)
profile.update_preferences()
if debug: print "done. - %r" % time.asctime()
return profile
# Somewhere else
self.profile = PyWebBot.FirefoxProfile(config['downloads'], config['handlers'])
self.driver = webdriver.Firefox(self.profile)
how to do this for Chrome ? i need the same settings
Save file to custom directory
Autosave (never ask)
Edit
def Google_desired_capabilities(path=os.getcwd()):
return {"prefs": {
"download.default_directory": path,
"download.prompt_for_download": False
},
"switches": ["-silent", "--disable-logging"],
"chromeOptions": {
"args": ["-silent", "--disable-logging"]
}
}
Update
chrome_options = webdriver.ChromeOptions()
chrome_options.prefs = PyWebBot.Google_desired_capabilities(config['downloads'])['prefs']
self.driver = webdriver.Chrome(path.join(config['drivers'],'chromedriver.exe'), chrome_options=chrome_options)

Categories