Skip to content

Instantly share code, notes, and snippets.

@Akonibrahim
Last active July 13, 2018 14:10
Show Gist options
  • Save Akonibrahim/7b66bb94f36701c90799be24fe9a064c to your computer and use it in GitHub Desktop.
Save Akonibrahim/7b66bb94f36701c90799be24fe9a064c to your computer and use it in GitHub Desktop.
Automation
import time
import pandas as pd
# Importing selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Open up chrome
browser = webdriver.Chrome(r"C:\webdriver\bin\chromedriver.exe")
# Get to the page
browser.get('https://dialogflow.com/')
## Remeber to the login manually
time.sleep(50)
# read the csv file
data_set = pd.read_csv('final_dataset.csv')
for i in range(len(data_set)):
# Click create intent
try:
elem = browser.find_element_by_id("multi-button")
print('Found <%s> element with that class name!' % (elem.tag_name))
elem.click()
except:
print('Was not able to find an element with that name.')
time.sleep(10)
# Type in intent name
try:
elem = browser.find_element_by_id("entity-name")
print('Found <%s> element with that class name!' % (elem.tag_name))
lister = data_set['Questions'][i].split()[0:4]
lister = '.'.join(lister)
elem.send_keys(lister)
except:
print('Was not able to find an element with that name.')
time.sleep(2)
# Type in the first column(Questions)
try:
elem1 = browser.find_element_by_xpath("//*[@id='intent-user-says-editor']/intent-user-says-editor/div[2]/div[1]/user-says-editor/div/div/div[1]/div")
print('Found <%s> element with that class name!' % (elem1.tag_name))
elem1.send_keys(data_set['Questions'][i])
except:
print('Was not able to find an element with that name.')
time.sleep(2)
# Type in the second column(Answers)
try:
elem2 = browser.find_element_by_xpath("//*[@id='prompt-empty']")
print('Found <%s> element with that class name!' % (elem2.tag_name))
elem2.send_keys(data_set['Answers'][i])
except:
print('Was not able to find an element with that name.')
time.sleep(2)
# click save
try:
elem3 = browser.find_element_by_id("multi-button")
print('Found <%s> element with that class name!' % (elem3.tag_name))
elem3.click()
except:
print('Was not able to find an element with that name.')
time.sleep(10)
# Going back to intents
try:
elem4 = browser.find_element_by_xpath("//*[@id='control-panel-menu']/li[6]")
print('Found <%s> element with that class name!' % (elem4.tag_name))
elem4.click()
except:
print('Was not able to find an element with that name.')
time.sleep(2)
print(i+1,"row completed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment