Monday, October 5, 2015

Switch Driver to FB Dialogue, Interact With It, Switch Back to Main Site

Interacting with social media dialogues is not a reason for trepidation. It's actually very easy.

FB_button = self.driver.find_element_by_css_selector("FB_button")
FB_button.click()
time.sleep(2)

#switch to FB dialogue, sign in.
main_site = self.driver.window_handles[0]
FB_dialogue = self.driver.window_handles[1]
if FB_dialogue:
    print "FB dialogue detected"
    self.driver.switch_to_window(FB_dialogue)
    FB_email = self.driver.find_element_by_id("email")
    FB_password = self.driver.find_element_by_id("pass")
    FB_login_button = self.driver.find_element_by_id("u_0_2")
    FB_email.send_keys("username@wherever.tld")
    FB_password.send_keys("password")
    FB_login_button.click()

time.sleep(2)
self.driver.switch_to_window(main_site)