0
votes
element = driver.find_element_by_xpath("/html/body/div[25]/div/div/div/div/div[1]/div/div/ul/li[3]/a/span/span").click();

I am trying this for the fb logout and giving me error .

NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"/html/body/div[25]/div/div/div/div/div[1]/div/div/ul/li[3]/a/span/span"}

6
u cant click on logout that appears after click on button? - noor
can you please give exact solution.that will help me lot. thanks - Mayank
i want to know in which condition u can not click on logout button...after appearing the logout or not? - noor
After Appearing the logout button. <span class="_54nh"> this is the logout class. thanks - Mayank

6 Answers

0
votes

I assume, after click on arrow button, Log Out button appers in ur code. So to click on that log Out button, use the below portion as cssSelector:

driver.find_element_by_css_selector('a[data-gt*='menu_logout']>span>span._54nh').click();
0
votes

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

driver = webdriver.Firefox() driver.get("https://facebook.com")

email = "email" password = "pass" login ="loginbutton" Drop = "userNavigationLabel"

emailelement = driver.find_element_by_name(email) passwordelement = driver.find_element_by_name(password) emailelement.send_keys("Email Address") passwordelement.send_keys("Password") loginelement = driver.find_element_by_id(login) loginelement.click() Dropelement = driver.find_element_by_id(Drop) Dropelement.click() Dropelement = driver.find_element_by_xpath("//[@id='userNavigationLabel']") logoutelement = driver.find_element_by_css_selector("a[data-gt="menu_logout"]span>span._54nh").click(

0
votes

This should work perfectly for you. Note that the time delay is very important.

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

    driver = webdriver.Chrome()
    driver.get("https://facebook.com")

    email = driver.find_element_by_name("email")
    password = driver.find_element_by_name("pass")
    email.send_keys("[email protected]")
    password.send_keys("mypassword")
    login = driver.find_element_by_id("loginbutton").click()

  logout1=driver.find_element_by_css_selector("#userNavigationLabel").click()
    time.sleep(35)
    logout2=driver.find_element_by_xpath("//li[12]/a/span/span").click()

    driver.close
0
votes

Python code for facebook logout using selenium

driver.find_element_by_css_selector("._w0d[action='https://www.facebook.com/logout.php?button_name=logout&button_location=settings']").submit()

Using the CSS selector method, select the logout element using the class "._w0d" and attribute for action="https://www.facebook.com/logout.php?button_name=logout&button_location=settings". This being a form, should be submitted, thus use the "submit" method.

0
votes

Hope this helps.

logout1=driver.find_element_by_css_selector("#userNavigationLabel").click()
time.sleep(5)

logout2=driver.find_element_by_css_selector("#js_8 > div > div > ul > li:nth-child(13) > a > span > span").click()
0
votes

Hope this help you:

from selenium import webdriver
import time

username = '[email protected]'
password = 'forgetmenot'

driver = webdriver.Chrome()
driver.get('https://www.facebook.com/')
time.sleep(1)

form_input_email = driver.find_element_by_id('email')
form_input_email.send_keys(username)
time.sleep(1)

form_input_password = driver.find_element_by_id('pass')
form_input_password.send_keys(password)

form_input_submit = driver.find_element_by_id('loginbutton')
form_input_submit.click()

input('Any key to quit')
driver.quit()

But first, install Chromium Driver from http://chromedriver.chromium.org. On Mac, you can install via brew (brew cask install chromedriver).