Using Selenium to write a Bot for the Skype Web Client

821 views
Skip to first unread message

Jonathan Schumann

unread,
Sep 7, 2015, 12:33:36 AM9/7/15
to Selenium Users
As some of you might know skype changed group chats from P2P to Cloud. This makes using Skype4Py impossible. My Idea was to use the WebClient of Skype with Selenium to create a bot which can interact with the people in a groupChat.
Ive already figured out how to Log in and Send Messages. My next goal is to have a loop which constanly saves the newest message in a string and analyze that string for certain keywords.


In the picture you can see that I pinned down the exact location of the newest message. The rule="log"< xyz > always shows the newest message that was send. However i am not able to figure out how to access that < xyz > string...
the class "ofclass" is not unique therefor I cannot use it for this. Is it possible to pin down the exact location and string via xpath? and if yes could someone help me with that?
Im using pyhton 2.7 for my programm.

Best regards,
Jonny

Krishnan Mahadevan

unread,
Sep 7, 2015, 1:01:56 AM9/7/15
to seleniu...@googlegroups.com
Jonathan,

I am going to assume that you have a lot of typos w.r.t identifying the element of interest for you.

From the screenshot, I am guessing that you are looking at how to identify 

<div class=‘offScreen’ data-bind=‘text:ariaForNewMessage()’ aria-live=‘assertive’ role=‘log’>blah blah chat text</div>

You can use something like this :

WebElement latestMsg = driver.findElement(By.xPath("//div[@class='offScreen' and @role='log’]”));
String text = (String) driver.executeScript(“return arguments[0].innerHTML;”, latestMsg);


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/179a8dd3-6006-4c13-b411-4a6cc15c60cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan Schumann

unread,
Sep 7, 2015, 9:17:58 AM9/7/15
to Selenium Users
Hi Krishnan.

Thank you for helping me. My Code so far is:

 from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Firefox()
browser.get('https://web.skype.com/en/')
time.sleep(8)
login_name = browser.find_element_by_name('username')
login_name.send_keys('---------')
login_password = browser.find_element_by_name('password')
login_password.send_keys('----------' + Keys.RETURN)
time.sleep(8)
input_messages = browser.find_element_by_name('messageInput')
input_messages.send_keys('Testing Output' + Keys.RETURN)
according to you my next step would be: latestMsg = browser.find_element_by_xpath("//div[@class='offScreen' and @role='log’]”)
and text = browser.executeScript(“return arguments[0].innerHTML;”, latestMsg);
I am using Pyhton and therefor hope that I converted the commands correctly.
What i noticed tho is that with every new Message a new Offscreen class is added so therefore //div[@class='offScreen' and @role='log’] is not unique if i understood it correctly. Doesnt that make it impossible?
Best Regards
Jonny

Krishnan Mahadevan

unread,
Sep 7, 2015, 10:50:58 AM9/7/15
to Selenium Users
Jonny,

I haven't worked with the Python bindings. So I don't know if the syntax is correct or not.

Here's what you can try doing to get past your problem.

Since the XPath results in more than 1 elements (which am guessing all represent chat messages), you could perhaps keep track of the list of messages that were already retrieved by your system and then use it to figure out what is your new message i.e., something like this :

When you begin, and use this xPath, you perhaps have only 1 message. So you add up the chat message to a list. Now when you poll, you would get a new message. You check if the message already exists in your list and find out the new message using that. The flip side of this approach is that, if someone sends the same message again, then this logic goofs up.

The other approach I can think of is, check if the timestamp can be enabled in the chat window [ I never used the web client of skype ]. If its available then maybe you could rely on that as well.






Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages