-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelenium chatbot improved v2
More file actions
42 lines (35 loc) · 1.55 KB
/
Copy pathSelenium chatbot improved v2
File metadata and controls
42 lines (35 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import logging
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
class ChatbotTest:
def __init__(self, url, message):
self.url = url
self.message = message
self.driver = None
def setup(self):
options = webdriver.ChromeOptions()
options.add_argument('--start-maximized')
self.driver = webdriver.Chrome(options=options)
def test(self):
try:
self.driver.get(self.url)
wait = WebDriverWait(self.driver, 10)
input_field = wait.until(EC.presence_of_element_located((By.XPATH, "//input[@class='chatbot-input']")))
input_field.send_keys(self.message)
input_field.send_keys(Keys.ENTER)
wait.until(EC.presence_of_element_located((By.XPATH, "//div[@class='chatbot-response']")))
response = self.driver.find_element_by_xpath("//div[@class='chatbot-response']")
logging.info(response.text)
except Exception as e:
logging.error("Error: " + str(e))
def teardown(self):
self.driver.quit()
if __name__ == '__main__':
logging.basicConfig(filename='chatbot.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
chatbot_test = ChatbotTest(url="https://example.com/chatbot", message="Hello, how are you?")
chatbot_test.setup()
chatbot_test.test()
chatbot_test.teardown()