Selenium AttributeError“list”对象没有属性发送键

2024-10-01 07:38:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用Selenium自动登录网站https://clientes.ecuabots.com/user/login

这是我的代码:

class EcuabotsTest(unittest.TestCase):

def setUp(self):
    self.driver =  webdriver.Chrome(executable_path='/mnt/c/Users/Barbara/Documents/Formación Continua/Selenium/chromedriver.exe')
    driver = self.driver
    driver.get('https://clientes.ecuabots.com/user/login')
    driver.maximize_window()
    #driver.implicitly_wait(15)

def test_search_email_input(self):
    email_field = self.driver.find_elements_by_xpath('//*[@id="input-15"]')
    email_field.clear()
    
    email_field.send_keys('email@email.com)



if __name__ == "__main__":
    unittest.main(verbosity=2)

但是当我尝试这种方法时,我出现了一个错误:AttributeError'list'对象没有属性send_键

  • 我试图使用email_field=self.driver.find_element_by_xpath('/[@id=“input-15”]”)(单数),但我得到了以下错误:selenium.common.exceptions.NoSuchElementException:Message:没有这样的元素:{“方法”:“xpath”,“选择器”:“/[@id=“input-15”]”

  • 我用id、CSS选择器和完整的XPath尝试了查找电子邮件输入,但不起作用

  • 我尝试使用电子邮件\u字段[0]。发送\u密钥('0')email@email.com)但我又犯了第一个错误

事先非常感谢您的帮助


Tags: httpsselfcomidfieldinputemaildriver
1条回答
网友
1楼 · 发布于 2024-10-01 07:38:55
  1. 您必须等待页面加载并在那里显示元素
  2. 您应该使用find_element_by_xpath,而不是find_elements_by_xpath
  3. 你的定位器错了

试试这个:

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

email_input_css = 'input[placeholder="Email Address"]'

wait = WebDriverWait(browser, 20)

email = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, email_input_css)))
email_field.clear()
email_field.send_keys('email@email.com)

相关问题 更多 >