selenium 提交表单成功,依然报错问题
澳门博彩导航网址
澳门博彩导航网址
当前位置 : 澳门博彩导航网址 > 澳门博彩导航网址大全

selenium 提交表单成功,依然报错问题

我正在用selenium模拟登录一个网站,但是当我已经填写完成帐号密码后,他依然报错。我想知道为什么。

代码如下:

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

from cut import cut_vcode

url = http://passport2.chaoxing.com/login?fid=1479&refer=http://i.mooc.chaoxing.com

driver = webdriver.Firefox
driver.geturl

wait = WebDriverWaitdriver, 10

span = wait.untilEC.visibility_of_element_locatedBy.ID, "nameNoteId"
span.click
# 输入帐号
unameId = wait.untilEC.visibility_of_element_locatedBy.ID, "unameId"
unameId.send_keysXX
# 密码
passwordId = wait.untilEC.visibility_of_element_locatedBy.ID, "passwordId"
passwordId.send_keysXXXXXX

# 保存验证码图片
driver.set_window_size1166, 741
vcode_path = ./main.png
vcode_out_path = ./main-cut.png
driver.save_screenshotvcode_path

cut_vcodevcode_path,vcode_out_path,430,343,502,374
os.systemtesseract main-cut.png ./abc
with open ./abc.txt as f:
    CAPTCHA = f.read
# 输入验证码
numcode = driver.find_element_by_idnumcode
numcode.clear
numcode.send_keysCAPTCHA

button = driver.find_element_by_class_namezl_btn
time.sleep3

button.click
time.sleep3
print driver.title

# lession = driver.find_element_by_class_nameMcon1img



# lession.click

time.sleep10

driver.close


报错:

Traceback most recent call last:
  File "/Users/Ru/Desktop/erya/main.py", line 40, in <module>
    button = driver.find_element_by_class_namezl_btn
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 410, in find_element_by_class_name
    return self.find_elementby=By.CLASS_NAME, value=name
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 744, in find_element
    {using: by, value: value}[value]
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
    self.error_handler.check_responseresponse
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_classmessage, screen, stacktrace
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"class name","selector":"zl_btn"}
Stacktrace:
    at FirefoxDriver.prototype.findElementInternal_ file:///var/folders/pl/64qs2gdd2fzcn35z_gzcn4_r0000gn/T/tmpvbGemj/extensions/fxdriver@googlecode.com/components/driver-component.js:10770
    at FirefoxDriver.prototype.findElement file:///var/folders/pl/64qs2gdd2fzcn35z_gzcn4_r0000gn/T/tmpvbGemj/extensions/fxdriver@googlecode.com/components/driver-component.js:10779
    at DelayedCommand.prototype.executeInternal_/h file:///var/folders/pl/64qs2gdd2fzcn35z_gzcn4_r0000gn/T/tmpvbGemj/extensions/fxdriver@googlecode.com/components/command-processor.js:12661
    at DelayedCommand.prototype.executeInternal_ file:///var/folders/pl/64qs2gdd2fzcn35z_gzcn4_r0000gn/T/tmpvbGemj/extensions/fxdriver@googlecode.com/components/command-processor.js:12666
    at DelayedCommand.prototype.execute/< file:///var/folders/pl/64qs2gdd2fzcn35z_gzcn4_r0000gn/T/tmpvbGemj/extensions/fxdriver@googlecode.com/components/command-processor.js:12608

NoSuchElementException
保错报的很清楚了吧 没你需要的元素

我似乎发现了原因,当我把尝试把下面的代码注释后,他不再报错。错误似乎是:当我输入完验证码,便自动提交跳转主页面了,不需要点击提交按钮。

所以在跳转的主页面无法找到class_name=zl_btn,便报错了。

#button = driver.find_element_by_class_namezl_btn
#time.sleep3
#button.click

广告位

澳门博彩导航网址