![](/img/trans.png)
[英]Not enough arguments error in Python, what should I do to fix this?
[英]What should i do to fix the NoSuchElementException error in my python code?
我试图进入特定的链接(在代码中给出)并使用用户ID和密码登录。 登录后,我想单击一个名为“查看所有xxx评论”的按钮。 我正在使用硒来完成这项任务。 不幸的是我说错了。
**追踪(最近一次通话):文件“ C:/Users/xxxx/.PyCharmEdu2018.1/config/scratches/scratch_2.py”,第16行,位于username_box = driver.find_element_by_id('emailInput-input')
selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“ method”:“ id”,“ selector”:“ emailInput-input”}(会话信息:chrome = 67.0.3396.99)(驱动程序信息:chromedriver = 2.40.565498(ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform = Windows NT 10.0.17134 x86_64)**
这是我的代码:
from selenium import webdriver
from getpass import getpass
from selenium.webdriver.support.ui import WebDriverWait
`
usr = input('enter your user name : ')
psd = input('enter the password : ')
url = "https://www.coursera.org/courses?authMode=login&languages=en&query=big+data&userQuery=big+data"
# create a new Chrome session
driver = webdriver.Chrome()
driver.get(url)
username_box = driver.find_element_by_id('emailInput-input')
username_box.send_keys(usr)
pass_box = driver.find_element_by_id('passwordInput-input') #FHSU
pass_box.send_keys(psd)
login_btn = driver.find_element_by_xpath('//*[@id="authentication-box-content"]/div/div[2]/div/div[1]/form/div[1]/button/span')
login_btn.submit()
driver.find_element_by_xpath('//*[@id="ratings"]/div[2]/button').click()
尝试使用另一个元素标识符,例如by_xpath
或by_class_name
。 可能就像@raviraja所说的那样,该元素可能尚未加载。 您已经导入了WebDriverWait
,只需使用WebDriverWait(driver, 10).until(EC.presence_of_element_located(By.ID, 'emailInput-input'))
。
只需确保from selenium.webdriver.support import expected_conditions as EC
并from selenium.webdriver.common.by import By
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.