0

I am trying to send a message as input to chatbot to check the response but when I am trying to send a message to a chatbot, I need to click on the input box where one can enter a message. But it is showing 'element not found error' (In the code I am throwing NoSuchElement exception) I think this is happening because of the driver not being able to switch control from the base webpage to the chatbot after we click on the chatbot.

Following is the snippet:

driver.find_element_by_xpath('/html/body/div/div').click()

time.sleep(2)

try: 
   driver.find_element_by_xpath('/html/body/div/div[3]/div[1]/div[1]/textarea').click().send_keys('hi')except NoSuchElementException:print('Input element not found')
0

I am not real expert in python but I think you are trying to make two action on single line using .click() and .send_key at the same time. I believe you should try something like:

    driver.find_element_by_xpath('/html/body/div/div').click()

    elem = driver.find_element_by_xpath('/html/body/div/div[3]/div[1]/div[1]/textarea')
    elem.send_keys('hi')

If you can share the page you are trying to automate I could have a deeper look might be some layer overriding your text area or the chat box is not in the view you need to scroll it up. Check the page here

  • Thanks Omar. I have tried your solution too but it still shows 'element not found' can't share webpage due to some privacy reasons of organization i work in. To be more specific it's a chatbot like any other website has, first you have to click on the icon, then click on the chtabox you want to enter message, then enter the text and click on send. But webdriver is not abel to find the chatbox itself after clicking on chatbot icon. – Shreyanka Manekar Mar 28 at 9:04
  • cannot you ask your developer to add an ID to the textarea and try to work in it by ID? – Omar Mughrabi Mar 28 at 9:15
0

I am not real expert in python but I think you are trying to make two action on single line using .click() and .send_key at the same time. I believe you should try something like

driver.find_element_by_xpath('/html/body/div/div').click()

Fills out the login page

elem= driver.find_element_by_xpath('/html/body/div/div[3]/div[1]/div[1]/textarea')
        elem.send_keys('hi')

If you can share the page you are trying to automate I could have a deeper look might be some layer overriding your text area or the chat box is not in the view you need to scroll it up. Check the page here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.