python没有这样的元素:无法找到元素{“method”:“id”,“selector”:“email”}

时间:2016-08-03 17:06:48

标签: python selenium-webdriver

我的python代码出现问题。我不断得到python没有这样的元素:无法定位元素{“方法”:“id”,“选择器”:“电子邮件”}

        self.driver.get(redirecturl)

        email = "testmail02015@gmail.com"
        Password = "Passw0rd123"
        emailFieldID = "email"
        passwordFieldID = "password"
        loginButtonXpath = "//button[@value='btnLogin']"

        self.driver.find_element_by_id(emailFieldID).send_keys(email)
        self.driver.find_element_by_id(passwordFieldID).send_keys(Password)
        self.driver.find_element_by_xpath(loginButtonXpath).click()

1 个答案:

答案 0 :(得分:3)

通常问题是$(document).ready(function(){ $("#adminValidate").submit(function(event){ event.preventDefault(); if($("#adminLogin").val() == "admin" && $("#adminPass").val()=="admin"){ window.location.href = "admin.html#adminPage2"; } else{ alert("Invalid username and/or password!"); } }); }); 在页面完全加载之前运行得太快。因此,请尝试等待元素出现(在示例中,它等待最多10秒;如果元素出现在前面则更少):

find_element

之后,您可以像往常一样使用... emailFieldID = "email" ... WebDriverWait(browser, 10).until(EC.presence_of_element_located(browser.find_element_by_id(emailFieldID))) self.driver.find_element_by_id(emailFieldID).send_keys(email)