how can i send facebook message using selenium webdriver
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);;
facebook selenium webdriver message
add a comment |
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);;
facebook selenium webdriver message
Debug your code step by step and see wheather elements are identified first
– Siva
Feb 5 '16 at 5:49
done,, i think the reason is, message area is not input box
– Manish
Feb 8 '16 at 14:03
add a comment |
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);;
facebook selenium webdriver message
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);;
facebook selenium webdriver message
facebook selenium webdriver message
edited Feb 5 '16 at 6:35
Shubham Jain
7,58152961
7,58152961
asked Feb 5 '16 at 5:42
ManishManish
112
112
Debug your code step by step and see wheather elements are identified first
– Siva
Feb 5 '16 at 5:49
done,, i think the reason is, message area is not input box
– Manish
Feb 8 '16 at 14:03
add a comment |
Debug your code step by step and see wheather elements are identified first
– Siva
Feb 5 '16 at 5:49
done,, i think the reason is, message area is not input box
– Manish
Feb 8 '16 at 14:03
Debug your code step by step and see wheather elements are identified first
– Siva
Feb 5 '16 at 5:49
Debug your code step by step and see wheather elements are identified first
– Siva
Feb 5 '16 at 5:49
done,, i think the reason is, message area is not input box
– Manish
Feb 8 '16 at 14:03
done,, i think the reason is, message area is not input box
– Manish
Feb 8 '16 at 14:03
add a comment |
3 Answers
3
active
oldest
votes
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
Thanks a lot for the answer.. but i never used "require 'selenium-webdriver'", could you please share any document to understand (as i am new in selenium) or any other method to solve it easily. Thanks in Advance
– Manish
Feb 8 '16 at 13:59
I did it in Ruby - you must have done it in Java .. thats all. However use the Xpaths you should be able to send message like i did.
– Makjb lh
Feb 11 '16 at 2:02
Xpath - '//div[@class="_1ia"]/descendant::div[@class="_5rpu" and @role="textbox"]' ---- And Send Keys Enter into the text box instead of click. It will work.
– Makjb lh
Feb 11 '16 at 2:03
Can you give me any Rep points? ..
– Makjb lh
Feb 11 '16 at 2:05
add a comment |
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);
add a comment |
I have used this code, it works for me.
driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);
Can you explain more?
– Lamar
Aug 29 '17 at 11:18
First, you need to identify text box locator and then use "driver.findElement(by.id()).sendkeys" method to send the text into the textbox, here Keys.ENTER will enter the text.
– sachit
Sep 4 '17 at 5:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35217070%2fhow-can-i-send-facebook-message-using-selenium-webdriver%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
Thanks a lot for the answer.. but i never used "require 'selenium-webdriver'", could you please share any document to understand (as i am new in selenium) or any other method to solve it easily. Thanks in Advance
– Manish
Feb 8 '16 at 13:59
I did it in Ruby - you must have done it in Java .. thats all. However use the Xpaths you should be able to send message like i did.
– Makjb lh
Feb 11 '16 at 2:02
Xpath - '//div[@class="_1ia"]/descendant::div[@class="_5rpu" and @role="textbox"]' ---- And Send Keys Enter into the text box instead of click. It will work.
– Makjb lh
Feb 11 '16 at 2:03
Can you give me any Rep points? ..
– Makjb lh
Feb 11 '16 at 2:05
add a comment |
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
Thanks a lot for the answer.. but i never used "require 'selenium-webdriver'", could you please share any document to understand (as i am new in selenium) or any other method to solve it easily. Thanks in Advance
– Manish
Feb 8 '16 at 13:59
I did it in Ruby - you must have done it in Java .. thats all. However use the Xpaths you should be able to send message like i did.
– Makjb lh
Feb 11 '16 at 2:02
Xpath - '//div[@class="_1ia"]/descendant::div[@class="_5rpu" and @role="textbox"]' ---- And Send Keys Enter into the text box instead of click. It will work.
– Makjb lh
Feb 11 '16 at 2:03
Can you give me any Rep points? ..
– Makjb lh
Feb 11 '16 at 2:05
add a comment |
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
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
answered Feb 5 '16 at 6:30
Makjb lhMakjb lh
277215
277215
Thanks a lot for the answer.. but i never used "require 'selenium-webdriver'", could you please share any document to understand (as i am new in selenium) or any other method to solve it easily. Thanks in Advance
– Manish
Feb 8 '16 at 13:59
I did it in Ruby - you must have done it in Java .. thats all. However use the Xpaths you should be able to send message like i did.
– Makjb lh
Feb 11 '16 at 2:02
Xpath - '//div[@class="_1ia"]/descendant::div[@class="_5rpu" and @role="textbox"]' ---- And Send Keys Enter into the text box instead of click. It will work.
– Makjb lh
Feb 11 '16 at 2:03
Can you give me any Rep points? ..
– Makjb lh
Feb 11 '16 at 2:05
add a comment |
Thanks a lot for the answer.. but i never used "require 'selenium-webdriver'", could you please share any document to understand (as i am new in selenium) or any other method to solve it easily. Thanks in Advance
– Manish
Feb 8 '16 at 13:59
I did it in Ruby - you must have done it in Java .. thats all. However use the Xpaths you should be able to send message like i did.
– Makjb lh
Feb 11 '16 at 2:02
Xpath - '//div[@class="_1ia"]/descendant::div[@class="_5rpu" and @role="textbox"]' ---- And Send Keys Enter into the text box instead of click. It will work.
– Makjb lh
Feb 11 '16 at 2:03
Can you give me any Rep points? ..
– Makjb lh
Feb 11 '16 at 2:05
Thanks a lot for the answer.. but i never used "require 'selenium-webdriver'", could you please share any document to understand (as i am new in selenium) or any other method to solve it easily. Thanks in Advance
– Manish
Feb 8 '16 at 13:59
Thanks a lot for the answer.. but i never used "require 'selenium-webdriver'", could you please share any document to understand (as i am new in selenium) or any other method to solve it easily. Thanks in Advance
– Manish
Feb 8 '16 at 13:59
I did it in Ruby - you must have done it in Java .. thats all. However use the Xpaths you should be able to send message like i did.
– Makjb lh
Feb 11 '16 at 2:02
I did it in Ruby - you must have done it in Java .. thats all. However use the Xpaths you should be able to send message like i did.
– Makjb lh
Feb 11 '16 at 2:02
Xpath - '//div[@class="_1ia"]/descendant::div[@class="_5rpu" and @role="textbox"]' ---- And Send Keys Enter into the text box instead of click. It will work.
– Makjb lh
Feb 11 '16 at 2:03
Xpath - '//div[@class="_1ia"]/descendant::div[@class="_5rpu" and @role="textbox"]' ---- And Send Keys Enter into the text box instead of click. It will work.
– Makjb lh
Feb 11 '16 at 2:03
Can you give me any Rep points? ..
– Makjb lh
Feb 11 '16 at 2:05
Can you give me any Rep points? ..
– Makjb lh
Feb 11 '16 at 2:05
add a comment |
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);
add a comment |
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);
add a comment |
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);
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);
edited Mar 31 '17 at 0:51
Fares M.
1,54611418
1,54611418
answered Mar 30 '17 at 22:31
Jainil ChauhanJainil Chauhan
83
83
add a comment |
add a comment |
I have used this code, it works for me.
driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);
Can you explain more?
– Lamar
Aug 29 '17 at 11:18
First, you need to identify text box locator and then use "driver.findElement(by.id()).sendkeys" method to send the text into the textbox, here Keys.ENTER will enter the text.
– sachit
Sep 4 '17 at 5:56
add a comment |
I have used this code, it works for me.
driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);
Can you explain more?
– Lamar
Aug 29 '17 at 11:18
First, you need to identify text box locator and then use "driver.findElement(by.id()).sendkeys" method to send the text into the textbox, here Keys.ENTER will enter the text.
– sachit
Sep 4 '17 at 5:56
add a comment |
I have used this code, it works for me.
driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+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);
edited Nov 21 '18 at 19:16
Zoe
11.3k73976
11.3k73976
answered Aug 29 '17 at 11:02
sachitsachit
1
1
Can you explain more?
– Lamar
Aug 29 '17 at 11:18
First, you need to identify text box locator and then use "driver.findElement(by.id()).sendkeys" method to send the text into the textbox, here Keys.ENTER will enter the text.
– sachit
Sep 4 '17 at 5:56
add a comment |
Can you explain more?
– Lamar
Aug 29 '17 at 11:18
First, you need to identify text box locator and then use "driver.findElement(by.id()).sendkeys" method to send the text into the textbox, here Keys.ENTER will enter the text.
– sachit
Sep 4 '17 at 5:56
Can you explain more?
– Lamar
Aug 29 '17 at 11:18
Can you explain more?
– Lamar
Aug 29 '17 at 11:18
First, you need to identify text box locator and then use "driver.findElement(by.id()).sendkeys" method to send the text into the textbox, here Keys.ENTER will enter the text.
– sachit
Sep 4 '17 at 5:56
First, you need to identify text box locator and then use "driver.findElement(by.id()).sendkeys" method to send the text into the textbox, here Keys.ENTER will enter the text.
– sachit
Sep 4 '17 at 5:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35217070%2fhow-can-i-send-facebook-message-using-selenium-webdriver%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Debug your code step by step and see wheather elements are identified first
– Siva
Feb 5 '16 at 5:49
done,, i think the reason is, message area is not input box
– Manish
Feb 8 '16 at 14:03