how can i send facebook message using selenium webdriver - facebook

I am able to login on facebook, able to open chat but unable to send any message
Below program code I have used:
//Login on FB >> Working fine
driver.findElement(By.xpath(".//*[#id='email']")).sendKeys("******#gmail.com");
driver.findElement(By.xpath(".//*[#id='pass']")).sendKeys("********");
driver.findElement(By.xpath(".//*[#id='u_0_l']")).click();
// click on message icon >> Working fine
driver.findElement(By.xpath(".//*[#id='u_0_h']/li[1]/div/a/span")).click();
//click on friends name, to whom i want to send message >> Working fine
driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/div/div/div[1]/div/div/div[2]/ul/li[5]/div/div[2]/div/div[3]/div/div[1]/div/div/ul/li[2]/a")).click();
Thread.sleep(5000);
//Send message >>>> here, i am not getting any response, code run without entered any message or error
driver.findElement(By.xpath(".//*[#class='_552h _35li _n4k']")).sendKeys("Hiii");
driver.findElement(By.xpath("/html/body/div/div[5]/div[1]/div/div/div[1]/div/div[1]/div[2]/div/div/div/div/div[4]/div[5]/div[1]/div/div/div[2]/div/div/div")).sendKeys(Keys.ENTER);;

I have used this code, it works for me.
driver.findElement(By.xpath("//div[contains(#class,'_5rpu') and #role='combobox']")).sendKeys("hi"+Keys.ENTER);

require 'selenium-webdriver'
#driver = Selenium::WebDriver.for :chrome
#driver.get 'https://www.facebook.com/fname.lname?fref=none'
a = #driver.find_element(:xpath, '//[#id="email"]').send_keys('aaa#gmail.com')
a = #driver.find_element(:xpath, '//*[#id="pass"]').send_keys('12345678')
a = #driver.find_element(:xpath, '//*[#value="Log In"]').click
sleep 5
a = #driver.find_element(:xpath, '//a[#href="/messages/fname.lname" and #role="button"]').click
sleep 2;p 'This is Where I clicked/initiated the Send Message '
a = #driver.find_element(:xpath, '//div[#class="_1ia"]/descendant::div[#class="_5rpu" and #role="textbox"]')
a.send_keys('Hi There') # This is where I entered the keys and Did Enter
a.send_keys:enter

The correct answer since the #role has changed is :
WebElement sendmsg = driver
.findElement(By.xpath("//div[#class='_1ia']/descendant::div[#class='_5rpu' and #role='combobox']"));
sendmsg.sendKeys("Just testing: using selenium webdriver" + Keys.ENTER);

Related

Handle messages one at time on python telebot

i'm using a script (.bat) who do some download based on a link received on telegram, but at my code it can run multiple times, but i need to handle one message at time, and every message took like 15minutes to complete.
my atual code:
def handle_text_doc(message):
print ("bot new link to download")
with open ("test.txt","r") as arquivo:
email = arquivo.read()
#print (email)
with open ("test.txt","w") as arquivo:
texto = str(message)
arquivo.write(texto)
with open ("test.txt","r") as arquivo:
email = arquivo.read()
subprocess.call([r'c:\downloads\fullrun.bat'])
print ("terminado")
i need that subprocess finished before it starts again, but sometimes i receive like 10 messages, and i need to solve the .bat file for every messsage i receive, one at a time.
sorry for bad english
So you should use async version of telebot - click here to know more
Then your code should be something like this
async def handle_text_doc(message):
print ("bot new link to download")
await with open ("test.txt","r") as arquivo:
await email = arquivo.read()
#print (email)
await with open ("test.txt","w") as arquivo:
texto = str(message)
await arquivo.write(texto)
await with open ("test.txt","r") as arquivo:
email = arquivo.read()
await subprocess.call([r'c:\downloads\fullrun.bat'])
print ("terminado")

How to control tracking options and tags when using Mailgun's SMTP option (i.e. not using their API)

I’m using python to send emails using Mailgun’s SMTP server. I wish to use Mailgun’s builtin ability to tag my messages, and to track open and click events.
I know this can be done using Mailgun’s send message API, by adding headers like o:tag, o:tracking, o:tracking-clicks and o:tracking-opens (as explained here: https://documentation.mailgun.com/en/latest/api-sending.html#sending)
However, seeing as I'm the SMTP gateway and not the API, I’m trying to understand how to achieve the same result - emails that are tagged and fully tracked in Mailgun.
Any thoughts on how it can be done?
This is my little script at the moment:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Found it!
The following X-Mailgun headers can be added:
https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-smtp
So my script would be:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
message["X-Mailgun-Tag"] = "<tag>"
message["X-Mailgun-Track"] = "yes"
message["X-Mailgun-Track-Clicks"] = "yes"
message["X-Mailgun-Track-Opens"] = "yes"
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Now my email is tagged (can be analysed on a tag level in Mailgun), and clicks are tracked.
Happy days!

sleekXMPP: Get list of looged in users on XMPP Server

I am new to python & sleekxmpp scripting and would like to know how to pass this iq stanza (XEP-0133: Service administration - Get Online Users) using python (mainly the node in below stanza):
http://xmpp.org/extensions/xep-0133.html#get-online-users-list
<iq from='bard#shakespeare.lit/globe'
id='get-online-users-list-1'
to='shakespeare.lit'
type='set'
xml:lang='en'>
<command xmlns='http://jabber.org/protocol/commands'
action='execute'
node='http://jabber.org/protocol/admin#get-online-users-list'/>
</iq>
What I tried:
iq = self .make_iq_get(queryxmlns='http://jabber.org/protocol/commands', ito=self.domain, ifrom=self.jid, iq='')
response = iq.send()
print ('response = %s' % response)
Running above code in python is always resulting in IqError.
Can anyone please explain how to pass above iq stanza's xmlns, action and node information into make_iq_get ??
Please Help!!
Following code has solved my above problem:
1st line of code returns you a form to be filled, 2nd line returns a session id which is used in last line of code
iq = self['xep_0050'}.send_command(domain, "http://jabber.org/protocol/admin#get-online-users-list")
sessionid = iq['command']['sessionid']
form = self.xmpp.plugin['xep_0004'].make_form(ftype='submit')
field = form.add_field(
ftype='hidden',
type='hidden',
var='FORM_TYPE',
value=ADMIN)
field['type'] = 'hidden'
form.add_field(var='max_items', value='100')
print self['xep_0050'}.send_command(domain, "http://jabber.org/protocol/admin#get-online-users-list", sessionid=sessionid, payload=form)

Share an app with Friends with Corona sdk free version

I am trying to share my app created in corona sdk free version in facebook. But no working example found on internet. It seems there is a change in facebook api or policy. Does any one have created app in corona sdk with facebook integration recently ? Can any one provide me referece to the way we can integrate the facebook.
I found another question sharing my app through facebook in corona Sdk but the link provided in answer is down. It would be greate= help.
Is there any update in facebook API ? as I am getting response null every time. can any one provide working example reference created recently ?
I tried the example provided by krs in following answer but it is not working for me.
https://developer.coronalabs.com/content/facebook
when I click on any of the feature like post Msg it goes to facebook page and after some processing it directly comes to the home page again nothing gets done. In log I ma getting response null.
following is screenshot of error.
any help will be great help to me.
EDIT
I had tried a lot but the same issue is there. I think facebook app configuration problem is there.
Can anyone provide detailed step by step information to configure an app and generate build in corona ? I am giving another 100 point bounty for this.
I hope this helps make a lua file and copy this code name it whatever you want
local facebook = require "facebook"
local json = require "json"
local _M = {}
local appId = "" -- put your app id string here
local message = ""
local access_token = ""
local fbCommand = ""
local LOGOUT = 1
local SHOW_DIALOG = 2
local POST_MSG = 3
local POST_PHOTO = 4
local GET_USER_INFO = 5
local GET_PLATFORM_INFO = 6
function showPopup(popupTitle,popupMessage)
native.showAlert( popupTitle, popupMessage, {"OK"} )
end
function listener( event )
if ( "session" == event.type ) then
if ( "login" ~= event.phase ) then
showPopup("Facebook share score failed!", "Please try again")
return
end
print(access_token)
access_token = event.token
if fbCommand == GET_USER_INFO then
facebook.request("me")
elseif fbCommand == POST_MSG then
facebook.request("me/feed", "POST" , {message = message} )
end
elseif ( "request" == event.type ) then
local response = event.response
print("Response: ",response)
if ( not event.isError ) then
if fbCommand == GET_USER_INFO then
response = json.decode( event.response )
elseif fbCommand == POST_MSG then
showPopup("Facebook share score", "You've successfully shared your score!")
end
else
showPopup("Facebook share score failed!", "Please try again")
end
end
end
function _M:postToWall(msg)
message = msg
fbCommand = POST_MSG
facebook.login( appId, listener, {"publish_stream"} )
end
function _M:shareGame()
message = "Juggler http://google.com/"
fbCommand = POST_MSG
facebook.login( appId, listener, {"publish_stream"} )
end
return _M
and when you want to share on use this function
local function FacebookShare(event)
if event.phase == "began" then
local FBManager
local message
FBManager = require( "Facebook" )
message = "" -- your message
FBManager:postToWall(message)
end
end
if user is not login it will call login facebook.
this works for me hope it solve your problem
There is facebook sample app from ansca labs. See that from the link below:
https://developer.coronalabs.com/content/facebook
And there is an integration in the app Ghosts-vs.-Monsters
https://github.com/ansca/Ghosts-vs.-Monsters
Keep coding......... :)

500 error when calling webservice through rhosync/rhodes

I am trying to call a web service in rhosync application.rb, I see a 500 error response in rhosync console .. and 'server returned an error' in BB simulator .. :(
Some info about my setup -
I have created a rhodes app that connects to a rhosync app when user enters user name and password and clicks on "login". I am calling this webservice through "authenticate" method of application.rb of the rhosync application ..
def authenticate(username,password,session)
Rho::AsyncHttp.get(:url => 'http://mywebserviceURL',:callback => (url_for :action => :httpget_callback),:callback_param => "" )
end
UPDATE
Instead of http:async, I tried consuming a soap based webservice and it worked just fine .. here is code if anyone cones here in search of a sample.. in application.rb of rhosync app
require "soap/rpc/driver"
class Application < Rhosync::Base
class << self
def authenticate(username,password,session)
driver = SOAP::RPC::Driver.new('http://webserviceurl')
driver.add_method('authenticate', 'username', 'password')
ret=driver.authenticate(username,password)
if ret=="Success" then
true
else
false
end
end
end
Application.initializer(ROOT_PATH)
You can typically find the problem if you crank up your log. Edit rhoconfig.txt in your app
set these properties -
# Rhodes runtime properties
MinSeverity = 1
LogToOutput = 1
LogCategories = *
ExcludeLogCategories =
then try again and watch the terminal output. Feel free to post the log back and I'll take a look.
You also might want to echo out puts the mywebserviceURL if you're using that as a variable, I trust you just changed that for the post here. Can you access the webservice if you hit it with a browser?
require "soap/rpc/driver"
class Application < Rhosync::Base
class << self
def authenticate(username,password,session)
driver = SOAP::RPC::Driver.new('http://webserviceurl')
driver.add_method('authenticate', 'username', 'password')
ret=driver.authenticate(username,password)
if ret=="Success" then
true
else
false
end
end
end
Application.initializer(ROOT_PATH)
in this what is done in add_method and authenticate method and where it to be written.