python-3.x 属性错误:"WebDriver"对象没有属性"find_element_by_id"

hkmswyz6  于 2022-12-24  发布在  Python
关注(0)|答案(1)|浏览(478)

这个问题的解决方案是不发送密钥我想要一个解决方案,这是网站链接:https://mahmoud-magdy.com/register

driver = webdriver.Firefox()
driver.get('https://mahmoud-magdy.com/register')
driver.find_element_by_id('first_name').send_keys(monster)
driver.find_element_by_id('last_name').send_keys(monster)
driver.find_element_by_name('phone').send_keys(phone)
driver.find_element_by_name('father_phone').send_keys(father_phone)
driver.find_element_by_name('email').send_keys(email)
driver.find_element_by_name('password').send_keys(password)
driver.find_element_by_name('password_confirmation').send_keys(password_confirmation)
driver.find_element_by_css_selector('button[type="submit"]').click()
print(phone)
driver.quit()

当我尝试将密钥发送到名字时,出现此问题

hrysbysz

hrysbysz1#

从Selenium 4.3版本开始,Selenium不再支持find_element_by_*方法。
您需要使用新语法。
在您的情况下,应如下所示:

driver = webdriver.Firefox()
driver.get('https://mahmoud-magdy.com/register')
driver.find_element(By.ID, 'first_name').send_keys(monster)
driver.find_element(By.ID, 'last_name').send_keys(monster)
driver.find_element(By.NAME, 'phone').send_keys(phone)
driver.find_element(By.NAME, 'father_phone').send_keys(father_phone)
driver.find_element(By.NAME, 'email').send_keys(email)
driver.find_element(By.NAME, 'password').send_keys(password)
driver.find_element(By.NAME, 'password_confirmation').send_keys(password_confirmation)
driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click()
print(phone)
driver.quit()

您将需要此导入来执行以下操作:

from selenium.webdriver.common.by import By

相关问题