1

I made a file with python to open the browser and search on google. When I go into my 'Python' directory and run the file it works just fine. I copied that file to my home directory and used the chmod 755 so that I can execute using ./filename but when I execute it does nothing, no errors occur though.

So why does the file not execute and bring up the browser when I use ./filename vs running the file in its home directory with python filename.py?

I am also getting this error now when trying to execute with ./filename format

./google.py: line 1: import: command not found from: can't read /var/mail/selenium ./google.py: line 4: syntax error near unexpected token (' ./google.py: line 4:search1 = ' '.join(sys.argv)[9:]' Code here:

'''
import sys
from selenium import webdriver
search1 = ' '.join(sys.argv)[9:]
driver = webdriver.Chrome(executable_path=r'/users/roughcaster/Downloads/chromedriver')
driver.get('https://www.google.com')
driver.maximize_window()
search = driver.find_element_by_xpath('//*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input')
search.click()
search.send_keys(search1)
submit = driver.find_element_by_xpath('//*[@id="tsf"]/div[2]/div[1]/div[3]/center/input[1]')
submit.click()
'''

1 Answers1

0

When you run script as ./filename shebang is used to detect what application should execute this script. Try to add #!/usr/bin/env python as the first line of the script

P. Dmitry
  • 1,123
  • 8
  • 26