1

When I am trying to use Selenium I am getting an error as:

nvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

my code :

driver = webdriver.Chrome('chromedriver\chromedriver.exe')
# request url
driver.get('https://jamalon.com/ar/best-seller-books-2019')
#give it some time
sleep(2)
## retrive , download html page
html = driver.page_source
#close
driver.close()

i try to do same solution here but i get same error :( InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium

liliy
  • 29
  • 1
  • 6

1 Answers1

0

First if you're using Pycharm then keep your chromedriver.exe in the location where your current python file is located.

Then use the below code:

from selenium import webdriver
import time
driver = webdriver.Chrome()

# request url
driver.get('https://jamalon.com/ar/best-seller-books-2019')
#give it some time
time.sleep(2)
## retrive , download html page
html = driver.page_source
print(html)
#close
driver.close()

Output:

enter image description here

Amar Kumar
  • 2,392
  • 2
  • 25
  • 33
  • 1
    Thank you Amar , i use Jupyter notebook ,, i try the cod but i get same error agian – liliy Mar 16 '20 at 19:00
  • Then include the chromedriver path inside the webdriver.Chrome(") function. – Amar Kumar Mar 16 '20 at 19:03
  • Just keep the format of the path like this :- driver = webdriver.Chrome(executable_path=r'C:\Users\GSC-30431\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe') – Amar Kumar Mar 16 '20 at 19:05
  • Or keep the chromedriver file along with the jupyter notebook file, both in the same path. and don't include path under the paranthesis eg- driver = webdriver.Chrome(). That will also work. – Amar Kumar Mar 16 '20 at 19:16
  • i change it to: driver = webdriver.Chrome(executable_path=r'C:\Users\LAM\Desktop\DSI\project3\project-3\chromedriver\chromedriver.exe') ... The page opens but with the error .. – liliy Mar 16 '20 at 19:17
  • chromedriver file with the jupyter notebook in the same file ..... i check (Python37-32\Lib\site-packages\) I didn't find selenium is this wrong – liliy Mar 16 '20 at 19:19