-1

Is there an error in this line? The following words appear in red, executable_path, options, and when converting the code to an exe file, an error appeared in the same line

    self.driver = webdriver.Chrome(executable_path="D:\driver\chromedriver.exe", options=chrome_options)
  • File "wati.py", line 69, in connect_to_whatsapp TypeError: WebDriver.__init__() got an unexpected keyword argument 'executable_path' – Ammar alghareeb Aug 03 '23 at 12:58
  • what do you mean converting the code to an exe file? turns red where? Did you receive an error when you ran it? if that error message you pasted as a comment was generated please put it in the actual question. and include more of the code to minimally expose the problem with needed information. – UpAndAdam Aug 03 '23 at 13:13

2 Answers2

2

try this:

    self.driver = webdriver.Chrome(executable_path=r"D:\driver\chromedriver.exe", options=chrome_options)

By adding the "r" character at the beginning of the string you make it a "raw string literal" the practical implication being that backslash characters "\" that would normally require escaping as "\\" can remain as "\" (single backslashes).

For more information, check out What does preceding a string literal with "r" mean?

JonSG
  • 10,542
  • 2
  • 25
  • 36
andexte
  • 181
  • 6
  • Can you explain why this would fix the issue? If you did, it would make a fine answer. – JonSG Aug 02 '23 at 12:53
  • Sure! by adding the "r" character at the begining of the path, it will change the path separator characters from "\" to "\\". I assume that is a blocker to run the code correctly. – andexte Aug 03 '23 at 11:08
0

You need to either escape backslashes (turn all single \into \\) or use normal slashes (/)

Biskweet
  • 130
  • 1
  • 9