(selenium + python) chatbots

oaqoa

Newbie
Joined
May 23, 2020
Messages
6
Reaction score
2
hello is anyone familiar with writing a chatbot using selenium?

currently i am trying to implement a chat bot to drive traffic to my social media accounts (in this case i am farming snapchat followers from various sources & sites via browser , hence selenium works well for this purpose
____________


my main issue is configuring my bot to recognize when a Web Element appears at the end of the chat interaction, so that it can execute (and send, and move on to new person ) messages in a loop, ( basically i would like it to wait until a status log appears on the page, when it appears i would like the bot to continue looping )

is using the isDisplayed feature in selenium in a while(true) loop a viable way to accomplish this?

if anyone is knowledgeable in Selenium please reach out!
brushing up on my python knowledge still too
 
If you want to detect when new element get added to the DOM you will have to inject javascript to the page.
Search how to inject javascript to a page from selenium if you don't know how.

To detect new changes you will be able do that with MutationObserver (javascript function)
 
Selenium has built in functions for waiting for an element. Will this not work for your purpose.

Waits in the docs:
https://selenium-python.readthedocs.io/waits.html
i believe this will work, only issue is that the element is appearing at random times, could be in the first 3 seconds of the chat interaction or could be in the first 30 seconds or minute. not sure how to run a constant check so that the element can be detected regardless of when it appears
 
The code will wait for the element to appear.

A quote from the first code snippet in the docs:

This waits up to 10 seconds before throwing a TimeoutException unless it finds the element to return within 10 seconds.
 
Code:
check= WebDriverWait(driver, 15);
check.until(EC.visibility_of_element_located((By.XPATH,"//input[contains(@class, 'emailbox-input')]")))

Edit the xpath to target the element that you are looking for.
It will wait 15 seconds expecting the element after which it timesout. You can may be use try/except according to how you are planning to use it.

Are we talking about Omegle here?
 
Code:
check= WebDriverWait(driver, 15);
check.until(EC.visibility_of_element_located((By.XPATH,"//input[contains(@class, 'emailbox-input')]")))

Edit the xpath to target the element that you are looking for.
It will wait 15 seconds expecting the element after which it timesout. You can may be use try/except according to how you are planning to use it.

Are we talking about Omegle here?
Similar chat messaging boards to omegle yes, also foreign websites with the same interface as omegle

The code will wait for the element to appear.

A quote from the first code snippet in the docs:

This waits up to 10 seconds before throwing a TimeoutException unless it finds the element to return within 10 seconds.
thank you @greydingo this solution did the trick
 
is using the isDisplayed feature in selenium in a while(true) loop a viable way to accomplish this?

Yes it is. Greydingo's solution is better but if you want you can with while loop in isDisplayed.

Basic logic;
func waitForDisplayed(element)
{
while(true)
try
if(element.isDisplayed) return
else sleep(5000)
catch() sleep(5000)
}

You can implement the logic in your case.
 
You can connect dialogflow cx using an API. Dialogflow CX has great potential.
 
Back
Top