I'm trying to get familiar with selenium. I decided to try to work with facebook
, and fulfill my profile with selenium
. But they use too much ajax
. It's not very complicated to fulfill my hometown and so on, but I don't really know how to upload an image. They have an ajax
form to choose between upload and webcam photo. And then I need to handle somehow an upload dialog... any ideas?
Asked
Active
Viewed 800 times
0

Vivek
- 910
- 2
- 9
- 26

oleg.foreigner
- 993
- 2
- 13
- 28
-
http://stackoverflow.com/questions/8665072/how-to-upload-file-picture-with-selenium-python ? – alexvassel Oct 09 '13 at 11:50
-
it's similar but not the same... there they just specify the path to the image and click Upload. You can go to facebook and look how they handle it. It is ajax form, then I get a dialog to choose a file... But thanx, now I have a starting point :) – oleg.foreigner Oct 09 '13 at 11:53
-
1As I can see, there is a form `fbTimelineFileForm` in the page source. It is possible to submit it with javascript. – alexvassel Oct 09 '13 at 11:59
-
@alexvassel submitting... ok, `execute_script`. and what about choosing a file? – oleg.foreigner Oct 09 '13 at 12:02
-
1How about the solution from the link above (with specifying the path...)? – alexvassel Oct 09 '13 at 12:04
-
will try it right now – oleg.foreigner Oct 09 '13 at 12:14
1 Answers
1
So ok... it was much more easy than I thought. All I needed was to wait until ajax box with file input loaded and then just send_keys
to it with image location.
try:
self.driver.find_element(By.CLASS_NAME, u"sx_53a53c").click()
WebDriverWait(self.driver, 10).until(ec.presence_of_element_located((By.CLASS_NAME, u"fbTimelineSelectorFileInput")))
WebDriverWait(self.driver, 10).until(ec.presence_of_element_located((By.NAME, u"pic")))
self.driver.find_element(By.NAME, u"pic").send_keys("~/Downloads/z_ed6e1de4.jpg")
except NoSuchElementException as nse:
print 'Error. Element not found! '.format(nse.message)
except:
print "Something went wrong."
import traceback
type_, value_, trace_ = sys.exc_info()
print traceback.format_tb(trace_)

oleg.foreigner
- 993
- 2
- 13
- 28