I have written a Python script utilizing Selenium to automatically upload raw GPS data files to OPUS [https://www.ngs.noaa.gov/OPUS/] for my research. I have a perfectly working Windows version and am now currently attempting to make it work on a Linux/Ubuntu 16.04 computer. Unfortunately, I keep getting an error when attempting to upload a file to the OPUS website. My code is as follows:
import os
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
directory = 'Documents/UNAVCO/HCC1/Y13' # Directory of GPS data files
# Loop through all files within the specified directory
for file in os.listdir(directory):
driver = webdriver.Chrome() # Open Chrome Driver
driver.get('https://www.ngs.noaa.gov/OPUS/') # Navigate to OPUS
website
time.sleep(5) # Wait 5 seconds
full_dir = os.path.join(directory,file)
print full_dir
file_upload = driver.find_element_by_name('uploadfile')
file_upload.send_keys(full_dir)
ID = 'TRM55970.00' # ID of GPS atenna
antenna_type =
driver.find_element_by_xpath("//option[contains(text(),'%s')]"%ID)
antenna_type.click() # Select the option
h = driver.find_element_by_name('height') #Find height element from
h.clear() # Clear element
h.send_keys('2.00') # Set value of height element
email = driver.find_element_by_name('email_address') # Find email
element from HTML
email.send_keys('[email protected]') # Set email element to
recipient
submit = driver.find_element_by_name('Static').click() # Submit
current data file
time.sleep(1)
os.remove(full_dir) # Delete file
driver.close() # Close the browser
print(file + ' ' + 'uploaded') # Visual of files uploaded
I receive the following error:
enter cTraceback (most recent call last):
File "/home/zacparra/OPUSpush.py", line 24, in <module>
file_upload.send_keys(full_dir)
File "/usr/local/lib/python2.7/dist-
packages/selenium/webdriver/remote/webelement.py", line 352, in
send_keys
'value': keys_to_typing(value)})
File "/usr/local/lib/python2.7/dist-
packages/selenium/webdriver/remote/webelement.py", line 501, in
_execute
return self._parent.execute(command, params)
File "/usr/local/lib/python2.7/dist-
packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-
packages/selenium/webdriver/remote/errorhandler.py", line 194, in
check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: unknown error: path is not absolute:
Documents/UNAVCO/HCC1/Y13/hcc11750.13d
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.26.436382
(70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.10.0-35-
generic x86_64)ode here
As aforementioned, a slightly modified version of the code works to perfection on a Windows OS. I have looked for alternative methods of uploading files, but have not found a proper solution to this problem. Any help would be greatly appreciated.