简体   繁体   中英

How I can send a message on Facebook using Selenium Driver in Python

I am trying to send a message to my FB friends using selenium in python. I've tried Element by Xpath, CSS Selector, Class but it doesn't work please help me how it would be I'm trying using

Message_button = browser.find_element_by_id("u_0_t")
Message_button.click()
time.sleep(10)

message = browser.find_element_by_xpath("//textarea[@class='luiTextareaAutogrow _552m']")
message.send_keys("Hi this is Mark how are you..!")
message.submit()
time.sleep(10)

Here is the FB Code

 <div class="fbNubFlyoutFooter"> <div class="_552h _n4k"> <textarea style="height: 15px;" class="uiTextareaAutogrow _552m" data-ft="{&quot;tn&quot;:&quot;+N&quot;}" onkeydown="run_with(this, [&quot;legacy:control-textarea&quot;], function() {TextAreaControl.getInstance(this)});"></textarea> </div> <div style="right: 0px;" class="_552n"> <div class="_10nr"></div> <div class="_6a _552o"> <form action="https://upload.facebook.com/ajax/mercury/upload.php" class="_vzk" title="Add Photos" method="post" data-reactid=".12"> <input name="attach_id" data-reactid=".12.0" type="hidden"> <input name="images_only" value="true" data-reactid=".12.1" type="hidden"> <div class="_m _4q60 _3rzn _6a" data-reactid=".12.2"><a tabindex="0" class="_4q61 _5f0v _509v" data-reactid=".12.2.0"><i class="_509w" alt="Camera" data-reactid=".12.2.0.0"></i></a> <input class="_n" name="attachment[]" multiple="" accept="image/*" title="Add Photos" data-reactid=".12.2.1" type="file"> </div> </form> </div> <div class="uiToggle _1tn3 emoticonsPanel" data-ft="{&quot;tn&quot;:&quot;+O&quot;}"><a class="_4vui" tabindex="0" title="Choose a sticker or emoticon" rel="toggle" role="button"><i class="_4l9x"></i></a> <div class="_5r8f panelFlyout uiToggleFlyout"> <div class="_5r8p"> <div style="padding:30px;text-align:center;" data-reactid=".13"><span class="img _55ym _55yq _55yo _5d9-" aria-label="Loading..." aria-busy="true" data-reactid=".13.0"></span> </div> </div> <div class="panelFlyoutArrow"></div> </div> </div> <div class="lfloat"></div> <div class="_5g2o"><a tabindex="0" aria-label="Send a Like" class="_3s0d" title="Send a Like" data-reactid=".10"><i class="_2y9i _30yy" data-reactid=".10.0"></i></a> </div> </div> </div>

Please help me am I using the correct method

you can use css_selector and Keys.ENTER as follows:

# enter your text by using css selector
driver.find_element_by_css_selector(".uiTextareaAutogrow._552m").send_keys("Merhaba, nasilsiniz?")

# you can send your message by sending native keyboard ENTER
driver.find_element_by_css_selector(".uiTextareaAutogrow._552m").send_keys(Keys.ENTER)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM