5

I am trying to click a button using selenium so I made it find the element with the xpath since i couldn't find the id . EDIT: I didn't think the rest of the code had anything to do with it but i added it just in case

This is The Code

import requests
import os
import selenium
from selenium import webdriver
os.system("cls")
print("                                         ")
print("______________     _____________         ________________")
print("| |         | |    |  |       | |        |______________|")
print("| |________ //     |  |  __   | |               | |")
print("| |________ \\\\     |  | |__|  | |               | |")
print("| |          | |   |  |       | |               | |")
print("| |__________| |   |__|_______|_|               |_|")

print("\u001b[34m Welcome To Movie Downloader")
print("\u001b[31m Please Make Sure To Not Put Every First Letter In Every Word Capital And Also Make Sure To Put Hyphens Instead Of Spaces Between Words, Also Put The Date The Movie Was Made")
print("\u001b[32m For Example: spider-man-homecoming-2017")


def Bot():
    URL = input("\u001b[34m What Movie Do You Want To Download:\n")
    r = requests.get("https://bila.egy.best/movie/" + URL + "/?ref=search-p1")
    if r.status_code == 200:
        print("\u001b[32m The Url Is Valid | Movie Has Been Found")
    else:
        print("\u001b[31m The Url Is Invalid")
    print("\u001b[0m")
    driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
    driver.get("https://bila.egy.best/movie/" + URL + "/?ref=search-p1")
    driver.find_element_by_xpath("//*[@id=watch_dl]/table/tbody/tr[2]/td[4]/a[1]").click()
Answer = input("Would You Like To Bot?")
if Answer == "Yes" or "yes" or "sure" or "Sure":
    Bot()

This Is The Error

Traceback (most recent call last):
  File "Movie_Download.py", line 32, in <module>
    Bot()
  File "Movie_Download.py", line 27, in Bot
    driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Which version of Chrome and ChromeDriver do you have? This sounds like a mismatch between browser and driver versions. – Greg Burghardt Dec 26 '19 at 14:49
  • i have chromedriver version ChromeDriver 79.0.3945.36 and chrome Version 79.0.3945.88 –  Dec 26 '19 at 14:56
  • https://stackoverflow.com/a/54663888/2397101 this may help – josifoski Dec 26 '19 at 15:34
  • If running chrome as an admin solves the problem, maybe change the folder where chrome is installed, or change file permissions so running as admin is not necessary? – Greg Burghardt Dec 26 '19 at 17:26

3 Answers3

5

You need to take care of a couple of things:

  • While passing the absolute location of chromedriver binary use a single forward slash along with the raw i.e. r switch. So the effective line of code will be:

    driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
    
  • Execute your @Test as non-administrator / non-root user.


Update

Another possible reason is Chrome is not installed in the default location as per the specification:

Chrome_default_location

Solution

There can be two approaches to solve this situation:

  • Uninstall Chrome and reinstall Chrome at default location.
  • Use binary_location property to point to the chrome binary location.

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
    driver = webdriver.Chrome(chrome_options=options, executable_path="C:/Utility/BrowserDrivers/chromedriver.exe", )
    driver.get('http://google.com/')
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • `` driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe') `` Still same error –  Dec 26 '19 at 15:44
  • @mohamedelgamal How about non-administrator / non-root user? – undetected Selenium Dec 26 '19 at 15:51
  • yup non administrator command prompt and it still doesnt work –  Dec 26 '19 at 15:59
  • @mohamedelgamal Checkout the updated answer and let me know the status. – undetected Selenium Dec 26 '19 at 16:03
  • i checked if chrome is in the default location and then i realized that i don't even have the AppData file –  Dec 26 '19 at 16:10
  • @mohamedelgamal So we nailed the main issue that you don't have the AppData file as I mentioned in my answer. Please install Chrome at the default location and let me know the status. – undetected Selenium Dec 26 '19 at 17:07
  • I was able to find the AppData file and the rest of the files the problem was it was listed as a hidden folder and when I navigate to the directory that you listed in the picture i was able to find the chrome application so I don't understand what was happening i reinstalled chrome but it never gave me the option to choose what directory it goes in. –  Dec 29 '19 at 12:47
1

If you are still getting this error then try to reinstall your chrome

It worked for me, I got the same issue, I tried all of the ways but still cannot fix it but after I reinstall my chrome browser It Worked!

azro
  • 53,056
  • 7
  • 34
  • 70
L4663R
  • 11
  • 3
0

you have to edit

driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")

to

driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")

you miss \

If you get the same error, try running as administrator

or

move chromedriver.exe to other path like c:/seleniumdriver/chromedriver.exe"and edit executable_path

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
joonghyup cha
  • 624
  • 3
  • 12