-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelenium chatbot improved
More file actions
34 lines (28 loc) · 1.29 KB
/
Selenium chatbot improved
File metadata and controls
34 lines (28 loc) · 1.29 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
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
chatbot_url = "https://example.com/chatbot"
chatbot_message = "Hello, how are you?"
try:
# Set up the Selenium webdriver
with webdriver.Chrome(options=options) as driver:
# Navigate to the chatbot URL
driver.get(chatbot_url)
# Wait for the chatbot to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@class='chatbot-input']")))
# Find the chatbot input field and enter a message
input_field = driver.find_element_by_xpath("//input[@class='chatbot-input']")
input_field.send_keys(chatbot_message)
input_field.send_keys(Keys.ENTER)
# Wait for the chatbot to respond
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@class='chatbot-response']")))
# Find the chatbot response and print it
response = driver.find_element_by_xpath("//div[@class='chatbot-response']")
print(response.text)
except Exception as e:
print("Error: " + str(e))
finally:
# Close the browser
driver.quit()