Automate outlook web app by using selenium , python
Asked Answered
C

2

1

I am trying to send email automatically from my office outlook web app. I have successfully automated the login process of outlook. But after login, there is no inspect element on new tab for sending mail. So how can i click on this new tab with selenium. Do i need to use some other framework for that.

Flow of automation is: Selenium will first click on webapps->email->india after that login in outlook web app and outlook web app will open after login

here is my code: here is my code:class LoginTest(unittest.TestCase):

def setUp(self):
    self.driver=webdriver.Firefox()
    userName="username"
    password="password"

    self.driver.get("http://sparshv2/")
    '''
    aa=self.driver.switch_to.alert;
    aa.send_keys(userName+ Keys.COMMAND + "t")
    aa.send_keys(password+ Keys.COMMAND + "t")
    aa.accept()
    '''
def test_outlook(self):
    driver=self.driver

    userName="username"
    password="password"


    #time.sleep(10)
    aa=driver.switch_to.alert;


    #aa.authenticate(userName, password)
    aa.send_keys(userName)
    #aa.send_keys(Keys.TAB)

    #ele_id=driver.execute_script("return window.document.activeElement.id")


    #time.sleep(5)
    aa.send_keys(password)
    #aa.send_keys(Keys.TAB)

    aa.accept()



    web_apps_link="Web Apps"
    emailId="Email **"
    country="India"



    webAppsElementId=WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_link_text(web_apps_link))
    webAppsElementId.click()
    #time.sleep(20)

    #webAppsElementId.send_keys(Keys.CONTROL + Keys.RETURN)
    aa=driver.switch_to.alert;
    aa.send_keys(userName+ str(KEY_ENTER))
    aa.send_keys(password+ str(KEY_ENTER))
    aa.accept()

    ahdElementId=WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_partial_link_text(emailId))
    ahdElementId.click()

    #time.sleep(20)

    driver.switch_to_window(driver.window_handles[1])
  #  country=input("You are from which country: india or outside india")
   # if(country.lower()=="india"):
    countryElementId=WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_link_text(country))
    countryElementId.click()
    #elif(country.lower()=="outside india"):
    #   countryElementId=WebDriverWait(driver,20).until(lambda driver:driver.find_element_by_link_text("Overseas"))
      #  countryElementId.click()
    driver.switch_to_window(driver.window_handles[2])  

    emailElementId = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(userNameId))
    emailElementId.clear()
    emailElementId.send_keys(userName)

    passwordElementId = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(passwordId))
    passwordElementId.clear()
    passwordElementId.send_keys(password)

    signElementId = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_class_name(signInButton))
    signElementId.click()
Conversationalist answered 8/8, 2016 at 5:16 Comment(5)
Could you share your code which have you tried??Pokeberry
ok here is my code:Conversationalist
where??? I'm not able to see...Pokeberry
I edited my post. Please look at it again.Conversationalist
hi Saurabh, Can you please help me? Actually i am not able to find any inspect element on any tab after login in outlook web app. Then how can i automate this.Conversationalist
O
1

Using Selenium for email generation is not the best idea. I advise you to look toward win32com.client or smtplib

In common this will looks like

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'to address'
mail.Subject = 'Message subject'
mail.body = 'Message body'
mail.send
Oke answered 8/8, 2016 at 7:27 Comment(1)
C
0

I used Firebug Plugin of Firefox to inspect and now I am able to see elements. Thanks everybody for providing the answer.

Conversationalist answered 31/8, 2016 at 17:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.