My script I have been writing has been working great. I just added the option so it would open a profile on chrome using this code.
options = webdriver.ChromeOptions
browser = webdriver.Chrome(executable_path=r"C:\Users\princess\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)
options.add_argument(r'user-data-dir=C:\Users\princess\AppData\Local\Google\Chrome\User Data')
options.add_argument('--profile-directory=Profile 1')
When used, I get this error code.
C:\Users\Princess\Desktop>CHBO.py
Traceback (most recent call last):
File "C:\Users\Princess\Desktop\CHBO.py", line 12, in <module>
browser = webdriver.Chrome(executable_path=r"C:\Users\princess\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)
File "C:\Users\Princess\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
desired_capabilities = options.to_capabilities()
TypeError: to_capabilities() missing 1 required positional argument: 'self'
How can I fix this?
To create and open a new Chrome Profile you need to follow the following steps :
chrome://settings/
opens up.Get the absolute path of the profile-directory in your system as follows :
C:\\Users\\Otaku_Wiz\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2
Now pass the value of profile-directory through an instance of Options with add_argument()
method along with key user-data-dir as follows :
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
Execute your Test
You can use options = Options()
or options = webdriver.ChromeOptions()
at place of options = webdriver.ChromeOptions
Otherwise you are pointing at an object (namely webdriver.ChromeOptions
), and not making an instance of that object by including the needed parenthesis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With