How to automate uploading photos to a website? - python

For the website 'https://web-en.wallapop.com/catalog/upload', if one tries to upload an add and scrolls down, photos can also be uploaded. How would I automate the uploading of a photo to this website with python?
I am currently writing a program that automatically creates adds on this website, however I do not know how to automate the uploading of a photo, located in my repository, to the website. I need to interact with the file explorer to pick the image and I do not know how to automate that. I do not even know if that is the right approach.
Any help is greatly appreciated!

driver.find_element_by_xpath('/html/body/tsl-root/tsl-upload/div/div/tsl-upload-product/form/div[2]/tsl-drop-area/div/div[2]/div/div[2]/label/input').send_keys(r'C:\Users\Nicolas Sanchez\3D Objects\Freelancer\Alberto\imagenes\i1473749533.jpg')
This works. This was my first thought initially however I was picking the wrong xpath selectors. This is the right xpath selector.

Related

Python - Download Excel file from clickable "XLS" button of website without using Selenium

I am trying to write a program that goes to the following site and downloads the Excel file that automatically downloads when clicking the XLS button on the bottom of the page. To be honest, I am quite new to programming.
Site: https://echa.europa.eu/assessment-regulatory-needs
At first I tried using Selenium to let the program click itself through the browser and really click on the button. However, I think the website detects the usage of automated software and I cannot bypass the disclaimer that appears when opening the website.
Then I read some answers on the same topic where it is possible by using the requests module. However, I could not get it to work.
One thing I think I understood from this anwer was that you need to get the site/server where the data is requested from by inspecting the button with F12 in the browser. I tried this, and thought I had it, however I cannot get the code to function. I learnt from this answer that you need to give the referer as well, bu I think the referer from this file ist only partially written out, as it is "https://echa.europa.eu/assessment-regulatory-needs".
This answer explained the network process more in detail, howver I am not able to recreate it. Also, to be honest i do not fully understand what the API is and how to search for it.
I also found this answer, but it does not work for me either.
So I am asking for help on this, as I think that my HTML, Java, Website, Python knowledge is too tiny to see what I have to change to be able to download the excel file.

Program for Google Sites in Python

I must get the URLs of all subpages found within one Google Site in the editor mode. I have a subpage for each Form(1 to 6 Upper) of all classes at school. However, I intend to automate any future changes using Python code. I must be able to access each page and upload photos to the subpages under each one. But, for that, I must get onto the subpage itself.
Basically, the web structure goes like this:
EVERYTHING -> CLASSES -> SUBJECTS
I have tried using Selenium for automation but that idea didn't work out since I cannot log in with Google once it enters automation mode since Selenium is active. I have tried using a program to simulate mouse motion and actually click on the subpages but it is far too complex and after several unsuccessful attempts, I gave up.
I need ideas on what I should do to access each subpage and retrieve its URL. I would appreciate if someone could help me because I am really stuck as I cannot hope to update the entire site manually on a weekly basis.
If someone could show me the code which would perform this task, I would appreciate it too much to express in words. No matter what, thanks very much!

Uploading Image with requests/selenium/pywinauto

Am trying to automate some postings on a couple different websites. Basically fill out my form and upload them to 3 sites with Selenium or requests. The image upload on this site opens a new window and asks you to specify the file path, or you can drag and drop the files. Here is what is looks like.
And without CSS here is what it looks like.
I abandoned requests earlier thinking there was no way I was going to be able to do anything with it. Moved to selenium and can click on the button and open the window but cannot actually place an image to upload in there. I have tried pywinauto and keep getting ElementNotVisible. I am having a hard time looking through the docs to find what to actually do. Where to go from here?
Try the below.
eleBrowse = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '//input[#type='file']')))
# replace the path below with the one which you want to upload. If you want to send multiple files use comma as separator.
eleBrowse.send_keys("path")

Read browser image and click without using selenium?

I was just trying to figure out how to get python to see the browser window and read the image there(I don't want to take a snapshot, if possible) process it and then click the relevant button on screen.
As a project I want to avoid selenium. I can't seem to find the correct library or any tutorials for this. Can someone tell me the library and possibly a tutorial?
I am on Ubuntu.
Thanks

Uploading a file into a popup window with selenium

I have searched the forums and found some information regarding this, but not quite with the problem I'm facing. I am automating the uploading of files to a website. Unfortunately, the website uses a counter for the id of the "browse" button. Using Selenium and Firebug, I was able to find another way to identify the button. I have exported the script into python to add variables so I can automate. However, the browse button opens a windows popup to select the file. The script is started out like this...
driver.find_element_by_xpath("//*[#type=\"file\"]").click()
driver.find_element_by_id("upfile_1405369589849").clear()
driver.find_element_by_id("upfile_1405369589849").send_keys("path\\file")
driver.find_element_by_id("upload_button").click()
In this, the upload button is clicked, the popup appears, and it sits there mocking me. I tried using the xpath in place of the id, but that didn't work. I tried the following, too...
driver.findElement(By.id()).send_keys("path\\file")
and tried this...
driver.find_element_by_id("upfile_*").send_keys("path\\file")
I cant seem to get the window to respond, other than it's mocking glare. Any help to squelch this would be very appreciated.
It can´t be done. One workaround is to get the development team to modify the AUT for you. Add a javascipt function into the page that will allow you to pass the filename to the handler without having to click the browse button.
If you can´t do that, I would suggest that you look into Sikuli that will allow you to interact with the windows prompt using pattern recognition (screenshots) of what you want to interact with.

Categories

Resources