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();
我正在尝试使用fb注销并给我错误。
NoSuchElementException:消息:无法找到元素:{"方法":" xpath","选择器":" / html / body / div [25] / DIV / DIV / DIV / DIV / DIV [1] / DIV / DIV / UL /锂[3] /一个/跨度/跨度"}
答案 0 :(得分:0)
我假设,在点击箭头按钮后,“注销”按钮会在您的代码中显示。因此,要单击该注销按钮,请使用以下部分作为cssSelector:
driver.find_element_by_css_selector('a[data-gt*='menu_logout']>span>span._54nh').click();
答案 1 :(得分:0)
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“)。单击(
答案 2 :(得分:0)
这应该对你有用。请注意,时间延迟非常重要。
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("example@gmail.com")
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
答案 3 :(得分:0)
使用selenium进行facebook登出的Python代码
driver.find_element_by_css_selector("._w0d[action='https://www.facebook.com/logout.php?button_name=logout&button_location=settings']").submit()
使用CSS选择器方法,使用类" ._ w0d" 和属性for action =" https:// www选择注销元素。 facebook.com/logout.php?button_name=logout&button_location=settings"。这是一个表格,应该提交,因此使用"提交"方法强>
答案 4 :(得分:0)
希望这有帮助。
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()
答案 5 :(得分:0)
希望这对您有帮助:
from selenium import webdriver
import time
username = 'foo@example.com'
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()
但是首先,从http://chromedriver.chromium.org安装Chromium Driver
。
在Mac上,您可以通过brew(brew cask install chromedriver
)进行安装。