Download word document in local folder using Rselenium - selenium

I am using R selenium to navigate through a website and eventually click a button that opens a dialog window to download the file. However, I want the file to automatically save in a different local folder.
My question is similar to this question.
Instead of using remDr <- remoteDriver(browserName = "firefox") I have tried
remDr <- remoteDriver(extraCapabilities = makeFirefoxProfile(list(
"browser.helperApps.neverAsk.saveToDisk"="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
)), but this gave an error that some local folder does not exist.
Note that I have no prior knowledge of Selenium and am quite new to programming.
All help welcome!
EDIT: because it it concerns a .docx file the correct MIME type appears to be: application/vnd.openxmlformats-officedocument.wordprocessingml.document. So I tried the following:
remDr <- remoteDriver(extraCapabilities = makeFirefoxProfile(list(
"browser.helperApps.neverAsk.saveToDisk"="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
))
but this gave following error:
Error in file(tmpfile, "rb") : cannot open the connection
In addition: Warning messages:
1: running command '"zip" -r9Xjq "C:\Users\PiKr\AppData\Local\Temp\RtmpApt5uQ\file19006f62c60.zip" "C:\Users\PiKr\AppData\Local\Temp\RtmpApt5uQ/firefoxprofile/prefs.js" ' had status 127
2: In file(tmpfile, "rb") :
cannot open file 'C:\Users\PiKr\AppData\Local\Temp\RtmpApt5uQ\file19006f62c60.zip': No such file or directory

I guess you must install the Rtools from the website and install the rtools before your proceed running the above program. Zipping action needs Rtools to perform. (Referring to the error 1)
Add the path to environment variable, if it doesn't add automatically

Related

Neo4j Desktop | Neo.ClientError.Statement.ExternalResourceFailed

Here, I simply introduce my situation about configuration:
System: Windows 11
Neo4j Desktop Version: 1.4.15
when I had finished that imports csv file to the C:\Users\ouyangkang\.Neo4jDesktop\relate-data\dbmss\dbms-00982ce7-0cb6-4ee7-b15a-1bc12ac5890e\import direcotry. I clicked open button and run following command:
LOAD CSV WITH HEADERS FROM 'file:///film_name.csv' AS row MERGE (n:name {name: row.name, encoding: row.encoding});
I got a error:
Couldn't load the external resource at: file:/C:/Users/ouyangkang/.Neo4jDesktop/relate-data/dbmss/dbms-00982ce7-0cb6-4ee7-b15a-1bc12ac5890e/import/film_name.csv
And I saw a similar error solution in Neo.ClientError.Statement.ExternalResourceFailed. I got a new error when configuration the neo4j.conf file
Couldn't load the external resource at: file:/film_name.csv
What's worse, I can't use the import function, it reminded that Trying to open undefined directory.
Please help me, thanks
I finially found the error that it is the file format question. The Neo4j not can use all csv file. You need to convert the file to guaratee the file format is standardized csv file with seperating by ','

Failed- Path too long error while downloading file in Chrome using selenium

I want to download file in my current working directory using selenium automation. But I am getting 'Path too long' error. The code I have written so far is:
os.chdir(os.path.dirname(__file__))
current_directory = os.getcwd()
windows_cwd = current_directory.replace('\\','\\\\')+'\\\\'
chrome_options = webdriver.ChromeOptions()
prefs = {'download.default_directory': windows_cwd,
'download.directory_upgrade': True,
'safebrowsing.enabled': False,
'safebrowsing.disable_download_protection': True
}
chrome_options.add_experimental_option('prefs',prefs)
browser = webdriver.Chrome(options=chrome_options)
My current working directory is:
C:\Users\US177\PycharmProjects\Plugin
where the path is too long.
But it successfully downloads to
C:\Users\US177\Desktop
failed-long path
I'm not exactly sure what your question is based on the information provided, but I'm guessing it's along the lines of "Why is this happening?", so I will address that question.
The maximum length of a file name in Windows is 260 characters. The file is able to download to your desktop because the name of the file (when appended to your path) does not exceed this limit. When trying to download to PycharmProjects\Plugin\ folder, the path has become too long.
While setting your download path, try using double backslash (ie. path\\to\\directory).
See this Github issue about programatically downloading from chrome

Can download but file will not unzip as expected

I'm attempting to access the Geometadb database which first involves download of the SQL library. I did that and then I got the Geometadb library.
library(GEOmetadb)
Next I need the Geometadb file which is where things start to go wrong. I issue this command as seen exactly in the tutorial: https://bioconductor.riken.jp/packages/3.0/bioc/vignettes/GEOmetadb/inst/doc/GEOmetadb.html
if(!file.exists('GEOmetadb.sqlite')) getSQLiteFile()
It should proceed to not only download a .gz zip file but also unzip the file. It downloads it but never unzips it. Instead I get the following error.
trying URL 'http://dl.dropbox.com/u/51653511/GEOmetadb.sqlite.gz'
Error in download.file(url_geo, destfile = localfile, mode = "wb") :
cannot open URL 'http://dl.dropbox.com/u/51653511/GEOmetadb.sqlite.gz'
In addition: Warning message:
In url(url_geo_2, open = "rb") :
cannot open: HTTP status was '403 Forbidden'
Just not sure what's going on here. Considering these are just the early tutorial steps I'm probably missing something really obvious but I'm hoping someone can help me out. Thanks!

Program using selenium fails after building with cx_freeze

I'm developing an automatic web tester using Selenium (v2.37.2). Program works properly until I run the test built with cxfreeze (there is also tkinter gui).
there is the init function
def initDriver(self):
if self.browser == FIREFOX:
profile = webdriver.FirefoxProfile(profile_directory=self.profile);
self._driver = webdriver.Firefox(firefox_profile=profile)
elif self.browser == CHROME:
self._driver = webdriver.Chrome(self.executable, chrome_options=profile)
elif self.browser == IEXPLORER:
self._driver = webdriver.Ie(self.executable)
Now when I build it using Cx_freeze I get this error
method redirectToBlank(...) calls initDriver(..) as the first thingSo how I pack the .xpi file to the library.zip file - which option in setup.py I have to use? And do I even have to this?
And the second strange thing is, that the other browsers work fine, when I execute the .exe file in by clicking on its icon, but when I run it from command line, I get errors even for chrome and IE. (Sorry that the traceback isn't complete)
All paths are relative from the executed file (no matter from where you run it),
Thank you for any ideas to solve this problem.
(method redirectToBlank(...) calls initDriver(..) as the first thing)
First issue solved
It's problem with selenium - FirefoxProfile - class, which tries to load webdriver.xpi as a normal file, but selenium pack all libraries to a zip file, so selenium can't find it.
Even forcing cx_freeze in setup file to add webdriver.xpi to a proper directory in zip won't help.
It is necessary to edit FirefoxProfile (in firefox_profile module) class for example like this
def _install_extension(self, addon, unpack=True):
"""
Installs addon from a filepath, url
or directory of addons in the profile.
- path: url, path to .xpi, or directory of addons
- unpack: whether to unpack unless specified otherwise in the install.rdf
"""
if addon == WEBDRIVER_EXT:
# altered lines
import sdi.env
WEBDRIVER_SUBSTITUTE = "path/to/unpacked/webdrive.xpi"
addon = os.path.join(os.path.dirname(__file__), WEBDRIVER_SUBSTITUTE)
# Original lines:
# addon = os.path.join(os.path.dirname(__file__), WEBDRIVER_EXT)
< the rest of the method >
Issue 2
OSError: win error 6: the handle is invalid problem wasn't caused by either cxfreeze or selenium. I run the final exe file from git bash. There's the problem. For some reason git bash doesn't open stdin for the program and that's why it fails. When I run it in standard windows command line, everything is ok or if i run it from git bash like program.exe < empty_file
what i did was remove selenium form packages list.
and put it inside includefiles, then it works.
like this :
includefiles = [(seleniumPackage,'')]
...
options = {'build_exe': {'includes':includes,
'excludes':excludes,
'optimize':2,
'packages':packages,
'include_files':includefiles,
...

File upload issue in CI

I am using CI and facing a problem while uploading file.
It gives a message mentioned below.
==================================================
Severity: Warning
Message: escapeshellarg() has been disabled for security reasons
Filename: libraries/Upload.php
Line Number: 1066
In some answers, I found that it is a server issue and CI has nothing to do with it. Now, is there any way to upload file bypassing the escapeshellarg() or is there any libraries I can use that doesn't require escapeshellarg()?
Please help.
I'm not sure which specific version of CI you're using, but the latest version does a check for that function before using it.
Take a look at the code here:
$cmd = function_exists('escapeshellarg')
? 'file --brief --mime '.escapeshellarg($file['tmp_name']).' 2>&1'
: 'file --brief --mime '.$file['tmp_name'].' 2>&1';
I'd say either upgrade or update the code manually.