0

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?

Vivek
  • 910
  • 2
  • 9
  • 26
oleg.foreigner
  • 993
  • 2
  • 13
  • 28

1 Answers1

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