Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from selenium import webdriver
- from selenium.common.exceptions import StaleElementReferenceException
- from selenium.webdriver.common.action_chains import ActionChains
- from selenium.webdriver.common.by import By
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.common.exceptions import NoSuchElementException
- class MeetingCreator:
- def __init__(self):
- super().__init__()
- self.username, self.password = self.get_username_password()
- self.driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
- def __del__(self):
- time.sleep(15)
- self.driver.close()
- def open_site(self, url):
- self.driver.get(url)
- self.driver.implicitly_wait(3)
- self.driver.maximize_window()
- def test_create_meeting_in_employee_buddy(self):
- try:
- url = "https://www.google.com/"
- self.open_site(url)
- self.login_to_employee_buddy()
- self.create_new_meeting()
- except NoSuchElementException as exceptions:
- print(exceptions)
- def login_to_employee_buddy(self):
- self.driver.find_element_by_id('login_emp_id').send_keys(self.username)
- self.driver.find_element_by_id('login_password').send_keys(self.password)
- self.driver.find_element_by_xpath("//button[@type='submit']").click()
- def get_username_password(self):
- username = None
- password = None
- with open("ebuddy_crdn.txt", "r") as file_open:
- for data in file_open.readlines():
- username, password = data.split()
- return username, password
- def create_new_meeting(self):
- self.action = ActionChains(self.driver)
- self.driver.find_element_by_link_text('Meeting').click()
- self.driver.find_element_by_link_text('Create meeting').click()
- self.meeting_creation_case_1()
- def meeting_creation_case_1(self):
- self.driver.find_element_by_id('add_new_purpose').click()
- self.driver.find_element_by_xpath("//li[text()='Conference']").click()
- self.driver.find_element_by_id(
- 'add_new_meeting_title').send_keys('Meeting title 4')
- self.driver.find_element_by_id('add_new_date').click()
- self.driver.find_element_by_xpath(
- "//tbody[@class='ant-calendar-tbody']//td[@title='January 29, 2020']").click()
- self.selection_of_meeting_place()
- def selection_of_meeting_place(self):
- self.driver.find_element_by_xpath(
- "//input[@type='radio' and @value='Indoor']").click()
- self.driver.find_element_by_id('add_new_room_id').click()
- self.driver.implicitly_wait(10)
- self.driver.find_element_by_xpath(
- "//ul//li[contains(text(),'OLD Office Ground Ground Floor Big')]").click()
- self.selection_of_start_time()
- def selection_of_start_time(self):
- self.driver.find_element_by_id('add_new_start_time').click()
- start_date = self.driver.find_element_by_xpath(
- "//div[@class='ant-time-picker-panel-combobox']/div[1]/ul/li[contains(text(),'12')]")
- self.action.move_to_element(start_date).perform()
- start_date.click()
- end_date = self.driver.find_element_by_xpath(
- "//div[@class='ant-time-picker-panel-combobox']/div[2]/ul/li[contains(text(),'51')]")
- self.action.move_to_element(end_date).perform()
- end_date.click()
- am_pm = self.driver.find_element_by_xpath(
- "//div[@class='ant-time-picker-panel-combobox']/div[3]/ul/li[contains(text(),'pm')]")
- self.action.move_to_element(am_pm).perform()
- am_pm.click()
- self.driver.implicitly_wait(10)
- self.selection_of_end_time()
- def selection_of_end_time(self):
- self.driver.find_element_by_xpath(
- "//input[@class='ant-time-picker-input' and @id='add_new_end_time']").click()
- tries = 0
- while tries < 3:
- try:
- WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(
- (By.XPATH, "//div[@class='ant-time-picker-panel-inner']/div[2]/div[1]/ul/li[contains(text(),'01')]")))
- start_date_2 = self.driver.find_element_by_xpath(
- "//div[@class='ant-time-picker-panel-inner']/div[2]/div[1]/ul/li[contains(text(),'01')]")
- ActionChains(self.driver).move_to_element(start_date_2).perform()
- start_date_2.click()
- end_date_2 = self.driver.find_element_by_xpath(
- "//div[@class='ant-time-picker-panel-inner']/div[2]/div[2]/ul/li[contains(text(),'51')]")
- ActionChains(self.driver).move_to_element(end_date_2).perform()
- end_date_2.click()
- am_pm_2 = self.driver.find_element_by_xpath(
- "//div[@class='ant-time-picker-panel-inner']/div[2]/div[3]/ul/li[contains(text(),'pm')]")
- ActionChains(self.driver).move_to_element(am_pm_2).perform()
- am_pm_2.click()
- tries = 3
- except StaleElementReferenceException:
- tries += 1
- self.selection_of_checkbox()
- def selection_of_checkbox(self):
- self.driver.find_element_by_class_name('ant-checkbox-input').click()
- self.login_button()
- def login_button(self):
- self.driver.find_element_by_xpath(
- "//button[@class='ant-btn ant-btn-primary ant-btn-lg ant-btn-block']").click()
- if __name__ == '__main__':
- meeting_creator = MeetingCreator()
- meeting_creator.create_meeting_in_employee_buddy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement