使用Selenium登录到Google帐户。尝试查找密码的xpath时出错

时间:2018-07-09 23:24:35

标签: python selenium

将硒与python 3.6一起使用时,需要制作一个基本脚本,让您使用硒登录到google acc。正常工作,直到您必须输入密码才能在页面中找不到该元素。这是我目前的尝试

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

print("Enter email")
e = input()
print("Enter pass")
p = input()
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get("https://keep.google.com/u/0/")
assert "Sign in" in driver.title
email = driver.find_element_by_id("identifierId")
email.clear()
email.send_keys(e)
submit = driver.find_element_by_id("identifierNext")
submit.click()
paswd = WebDriverWait(driver, 5).until(* 
if paswd == True:
    print("yay")
else:
    print("false")
paswd = driver.find_element_by_xpath("//input[@type='password']")
paswd.send_keys(p)
submit = driver.find_element_by_class_name("CwaK9")
submit.click()

*EC.presence_of_element_located((By.XPATH, "//input[@type='password']")))

*无法格式化以上部分的代码,因此在代码块之后继续执行。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

使用其他预期条件等待。代替 presence_of_element_located ,使用 element_to_be_clickable

paswd = WebDriverWait(driver, 5).until(EC. element_to_be_clickable((By.XPATH, "//input[@type='password']")))