I want to upload a file for Python Selenium however, the send_keys method (sending the keys with the directory of your file) does not work, I get a 'Message: element not interactable'. This is due to the fact that my upload button does not contain an 'input' on its html code. The code I currently have allows you to click on the 'upload files' button which then opens the little Mac Os window. After that, I have no idea what I can do. It is quite obvious that the send_keys method does not work.
The website I'm using also allows drag and drop, however I have been told that the drag and drop for Selenium does not work.
I was reading a lot about it but I couldn't find a solution specific to Python. A lot of the solutions referred to Java but I couldn't find any for Python. Anything I could do?
Here is the code I have:
button8 = driver.find_element_by_xpath("//[contains(#id,'FileName') and contains(#class,'x-btn')]")
button8.click()
time.sleep(1)
button9 = driver.find_element_by_xpath("//[contains(#id,'ext-comp-1056') and contains(#class,'x-btn')]")
button9.click()
button9.send_keys('/Users/sebastiendupont/Desktop/Screen Shot 2019-08-26 at 4.12.03 PM')
Here is the HTML code of the 'upload' button, I replaced the < with ( and > with ), because otherwise StackOverflow wouldn't display the html code
(table id="ext-comp-1056" cellspacing="0" class="x-btn btn-right upload-files x-btn-noicon" style="width: 100%; position: relative; z-index: 1;")(tbody class="x-btn-small x-btn-icon-small-left")(tr)(td class="x-btn-tl")(i) (/i)(/td)(td class="x-btn-tc")(/td)(td class="x-btn-tr")(i) (/i)(/td)(/tr)(tr)(td class="x-btn-ml")(i) (/i)(/td)(td class="x-btn-mc")(em class=" x-unselectable" unselectable="on")(button type="button" id="ext-gen179" class=" x-btn-text")+ Upload files...(/button)(/em)(/td)(td class="x-btn-mr")(i) (/i)(/td)(/tr)(tr)(td class="x-btn-bl")(i) (/i)(/td)(td class="x-btn-bc")(/td)(td class="x-btn-br")(i) (/i)(/td)(/tr)(/tbody)(/table)(
The codes sends the following classic message:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Please advise that I am very beginner at Python and Selenium but I have used complex codes.
Thank you!
You can use external tool AutoIT. You have to write script in AutoIT editor first and then compile it so it will generate .exe file.
After that you have to execute that .exe file in python using below code
import subprocess
subprocess.Popen(<path to AutoIT .exe file>)
Related
I have a link from microsoft one drive which is generated when we upload file pythonically. I have linked this link to a button whichis supposed to show the file but not download however on click it is donloading the file so i neeed help regarding how to prevent download but show the excel file linked. Below is react code I have been using
function Files(props){
let getFileOnClick=(fileAddress)=>{
window.location.href=fileAddress
}
return(
<button style={{float:'right'}} onClick = {()=>getFileOnClick(props.link)} className="btn btn-primary">
Get File
</button>
)
}
In index.html I got the following button:
<button id="btn_file" type="button" class="btn btn-default" onclick="getFile()"><span class="glyphicon glyphicon-file"></span></button>
In my javascript, picoreflow.js, I have this function:
function getFile()
{
var cmd = {"cmd":"DL"};
ws_control.send(JSON.stringify(cmd));
}
And in my picoreflowd.py, this is located in handle_control():
elif msgdict.get("cmd") == "DL":
log.info("Download command received")
static_file("downloadMe.txt", root='/home/pi/V2.3_Test/', download = "downloadMe.txt")
This is my github directory, which has the complete code: https://github.com/Ritzerk/V2.3_Test
I'm trying to work on open-source software, but I don't know anything about web-server. I tried to use static_file like suggested here: Binary file download
But its hard to know what I am doing wrong, since I have no website experience...
What's wrong with the way I am trying to download downloadMe.txt? The button doesn't even display on the website when I load it.
The file is located in the given directory. The V2.3_Test is located in /home/pi/.
I'm using an AutocompleteInput widget in a jupyter notebook. The autocompletion itself is working fine but I have an issue with the output.
Issue circled in red
Is it possible somehow to be able to see the ouput of the autocompletion without having to scroll (which is really not user friendly) ? (resizing the output cell of the notebook, autofiting the cell, option of the AutocompleteInput widet)
this is what i've done at the moment:
input_widget = AutocompleteInput(completions=list(df_competences['libelleCompetence']), title='Chercher une compétence', placeholder='Chercher une compétence', sizing_mode='scale_height', css_classes=['my_autocomplete_class'])
show(input_widget)
I've been looking a lot of possibilities but not founding a way to do this...
In case someone fall on the same issue as me, here is how I manged to fix it:
I'm getting the HTML code generated by bokeh, remove the class used by bokeh and replacing it with my own one. Then, you just need to create your own css class to make the autocompletion output suitable.
Here is the code:
from IPython.display import HTML
input_widget = AutocompleteInput(completions=list(df_competences['libelleCompetence']), title='Chercher une compétence: ', placeholder='Chercher une compétence', sizing_mode='scale_both', css_classes=['my_autocomplete_class'])
script, div = components(input_widget)
div = div.replace('bk-root', 'my_class')
div = div.replace('<div class="my_class"', '<div class="my_class" style="width: 100%; max_height: 500;"')
HTML(script + div)
Add a display HTML command, where you specify the min-height of the displayed suggestion box:
from IPython.core.display import display, HTML
input_widget = AutocompleteInput(completions=list(df_competences['libelleCompetence']), title='Chercher une compétence', placeholder='Chercher une compétence', sizing_mode='scale_height', css_classes=['my_autocomplete_class'])
display(HTML('<style> .bk-root[id] { min-height:100pt } </style>'))
show(input_widget)
I have a form in html with action = "pyth.py"
and pyth.py is
#!/usr/bin/python
print('Content-type: text/html\r\n\r')
print('<html><head></head><body>My first page</body></html>')
so when i click submit in form it should run the pyth.py and should give me an html output. but it is not. please help me
You have to run the python script in cgi-bin of your webserver. Your html form action should be action="/cgi-bin/pyth.py". Check out this tutorial.
When I “copy an image” on the web (by highlighting the image and ctrl+C) and then passed it into the text view of the HTML WYSIWYG editor (not the source code editor) the picture is displayed. Even though I paste in the text editor ( source code editor), the content of the clipboard is understood by the editor as an html code.
For example, if I simply paste “<img src="someURL" />in the text editor, it will be added in the source code as “<p><img src="someURL" /></p>” so this clipboard isn’t understood by the editor as an html code.
So how should I modify the content of my clipboard so that an HTML WYSIWYG editor understand it as an html code even though I am pasting it in the text view (not source code editor)?
What I want to do in more details:
when I have the URL of an image stored in my clipboard, I want to be able to add the image to the HTML WYSIWYG editor without having to switch to the source code editor. So I would like to transform the content of my clipboard (by adding some code before and after the URL) so it is understood as HTML code (just like the example mentioned above) by my HTML WYSIWYG editor.
Edit: to better target the answer here is what I try to achieve. When I use shareX to upload a picture, ShareX store automatically this (private) shareable URL in the clipboard. https://drive.google.com/open?id=XXXX
This code convert it in an embedded format. But I'm still looking for a way to store that as html format.
#URL_to_Picture.py
#
#(xxx=FileID)
#
#You need that kind of URL to be able to embed the picture in an editor: https://drive.google.com/uc?export=view&id=XXXX
#
#This script does a part of the job by converting Google drive URL into an embedded (and permanent) link:
from jaraco import clipboard
UrlShareX = clipboard.paste_text()
UrlShareX=UrlShareX.replace("https://drive.google.com/file/d/", "")
UrlShareX=UrlShareX.replace("/view?usp=drivesdk", "")
UrlShareX=UrlShareX.replace("/view?usp=sharing", "")
UrlShareX=UrlShareX.replace("https://drive.google.com/open?id=", "")
URL= '<img src="https://drive.google.com/uc?export=view&id={}" />'.format(UrlShareX)
clipboard.copy_html(URL)
To try on ShareX:
You must set the access to Google drive in ShareX menu:
destination/destination settings/google drive.
You must set the ShareX menu: “after upload task” to “copy URL to
clipboard”
I want to be able to add the image to the HTML WYSIWYG editor without having to switch to the source code editor
AHK solution: use a hotkey like ctrl+shift+v
you have plain text in clipboard: https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg?v=47faa659a05e
go in WYSIWYG editor and press ctrl+shift+v, it will be pasted in HTML format
HTML format is a clipboard format, so an image will be shown.
what you need is here: WinClipv2\imgSrc to HTML Format\src in clip.ah2
I put the code in a repo because there's a library to include:
https://github.com/FuPeiJiang/WinClipv2
READ the README.md
You can do this:
Install HtmlClipboard : copy the script, save it as HtmlClipboard.py in C:\Python##\Lib\site-packages\
Save the script below as image_link_as_html.py(I used some of your code in your question):
Create a shorcut for the script in step to (right click on the file image_link_as_html.py, and select create a shorcut)
Right click on the shorcut, select Properties, and and add a keyboard shorcut in Shorcut key.
That's it. When you have an image url in our clipboard, you can just press your keyboard shorcut and you can paste your image directly in the html mode of you editor.
image_link_as_html.py (Python34):
from tkinter import Tk
root = Tk()
root.withdraw()
image_url = root.clipboard_get()
# send <img src="https://image_url" alt="" /> to an "HTML format clipboard"
import HtmlClipboard
HtmlClipboard.PutHtml("<img src=\"http://"+image_url+" \" alt=\"\"/>")
To address the part about ShareX, you could use this scrip instead:
from tkinter import Tk
root = Tk()
root.withdraw()
UrlShareX = root.clipboard_get()
# remove everything except the file google ID: this part is not needed
UrlShareX=UrlShareX.replace("https://drive.google.com/file/d/", "")
UrlShareX=UrlShareX.replace("/view?usp=drivesdk", "")
UrlShareX=UrlShareX.replace("/view?usp=sharing", "")
UrlShareX=UrlShareX.replace("https://drive.google.com/open?id=", "")
UrlShareX=UrlShareX.replace("/view", "")
# send <img src="https://drive.google.com/uc?export=view&id=xxx " alt="" /> to an "HTML format clipboard"
import HtmlClipboard
HtmlClipboard.PutHtml("<img src=\"https://drive.google.com/uc?export=view&id="+UrlShareX+" \" alt=\"\"/>")