how can i send facebook message using selenium webdriver












0















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);;









share|improve this question

























  • 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
















0















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);;









share|improve this question

























  • 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














0












0








0


1






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);;









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












3 Answers
3






active

oldest

votes


















2














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


**Screen shot**






share|improve this answer
























  • 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



















0














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);





share|improve this answer

































    0














    I have used this code, it works for me.



    driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);


    enter image description here






    share|improve this answer


























    • 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











    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    2














    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


    **Screen shot**






    share|improve this answer
























    • 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
















    2














    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


    **Screen shot**






    share|improve this answer
























    • 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














    2












    2








    2







    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


    **Screen shot**






    share|improve this answer













    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


    **Screen shot**







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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



















    • 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













    0














    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);





    share|improve this answer






























      0














      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);





      share|improve this answer




























        0












        0








        0







        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);





        share|improve this answer















        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);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        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























            0














            I have used this code, it works for me.



            driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);


            enter image description here






            share|improve this answer


























            • 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
















            0














            I have used this code, it works for me.



            driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);


            enter image description here






            share|improve this answer


























            • 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














            0












            0








            0







            I have used this code, it works for me.



            driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);


            enter image description here






            share|improve this answer















            I have used this code, it works for me.



            driver.findElement(By.xpath("//div[contains(@class,'_5rpu') and @role='combobox']")).sendKeys("hi"+Keys.ENTER);


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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



















            • 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


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen