【发布时间】:2019-07-18 09:56:38
【问题描述】:
option = ChromeOptions()
chrome_prefs = {}
driver = Chrome(chrome_options=option) #getting the web driver object
try:
url="https://www.groupon.fr/merchant/center/"
driver.get(url)
driver.maximize_window()
email="xyz"
password="abc"
email_box=WebDriverWait(driver,10).until(lambda x: x.find_element_by_id("emailInput"))
email_box.send_keys(email)
password_box=WebDriverWait(driver,10).until(lambda x: x.find_element_by_id("passwordInput"))
password_box.send_keys(password)
attempts=0
while True:
try:
submit = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CLASS_NAME,"submitButton button-primary button-cta")))
driver.execute_script("arguments[0].click();", submit)
break
except:
traceback.print_exc(file=sys.stdout)
attempts+=1
if (attempts>3):
raise Exception("Error")
continue
finally:
driver.quit()
输出
Traceback(最近一次调用最后一次):文件 “”,第 22 行,在提交 = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CLASS_NAME,"submitButton button-primary button-cta"))) 文件 "C:\Users\sheik\Anaconda2\lib\site-packages\selenium\webdriver\support\wait.py", 第 80 行,直到引发 TimeoutException(消息、屏幕、堆栈跟踪) 超时异常:消息:
我实际上是在尝试登录此页面,在填写了电子邮件和密码后,虽然我使用了正确的按钮类名,但我无法找到提交按钮。我也从 xpath 尝试过,但没有成功。
我的代码有什么问题?The html of the page
【问题讨论】:
-
它应该做什么?您几乎没有提供任何信息。每个人都有比试图弄清楚你的代码应该做什么更好的事情要做。请编辑您的问题以提供背景和上下文。
-
如果你也分享部分的html代码就好了。
-
我已更新查询。附上页面的html图像。自从我第一次在这里发帖以来,请多多包涵,我正在为此苦苦挣扎。
-
问题是你正在使用
By.CLASS_NAME,但是发送了3个类名,“submitButton button-primary button-cta”。要么选择三个中的一个,要么将其转换为 CSS 选择器并使用所有三个,例如贾斯汀的回答。
标签: python selenium automation