Mathematica Asked on July 8, 2021
I’m downloading a file by clicking a button from chrome with the WebDriver functionality:
sess = StartWebSession[Visible->True]
WebExecute[sess, "ClickElement" -> el] (* el is download button *)
This works just fine, and when it finishes it gives a success object:
Success["ClickElement", Association[
"MessageTemplate" :> "`command` was successful.",
"MessageParameters" -> Association["command" -> "ClickElement"],
"Element" -> "0.5797105527746262-24"]]
My question is two-fold:
sess = StartWebSession[Visible->False];
WebExecute[sess,
"OpenPage" -> "https://datarepository.wolframcloud.com/resources/Patient-Medical-Data-for-Novel-Coronavirus-COVID-19"];
a = WebExecute[sess, "LocateElements" -> "Tag" -> "a"];
p = Position[WebExecute[sess, "ElementText" -> a],
"Source Notebook"][[1, 1]];
WebExecute[sess, "ClickElement" -> a[[p]]]
Regarding that your code does not work with StartWebSession[Visible->False]
seems to be a bug.
Here is my code that works with StartWebSession[Visible->False]
but uses URLDownloadSubmit
instead of WebExecute
. If everything goes OK and the file is downloaded you get no message, if the file does not exist or something goes wrong you get a warning message. You can specify your own name of downloaded file and its path instead of "C:file.nb"
. So this answer both of your questions.
sess = StartWebSession[Visible -> False];
WebExecute[sess,
"OpenPage" ->
"https://datarepository.wolframcloud.com/resources/Patient-Medical-
Data-for-Novel-Coronavirus-COVID-19"];
a = WebExecute[sess, "LocateElements" -> "Tag" -> "a"];
p = Position[WebExecute[sess, "ElementText" -> a],
"Source Notebook"][[1, 1]];
URLDownloadSubmit[
WebUnit`Private`attribute[
sess /@ {"SessionID", "Browser", "URL"}, a[[p]]["ElementId"],
"href"], "C:file.nb",
HandlerFunctions -> <|"ConnectionFailed" -> MessageDialog|>,
HandlerFunctionsKeys -> "StatusCode"]
Correct answer by azerbajdzan on July 8, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP