|
我试过用selenium录制脚本,id显示的是kw没错,但为何在我的代码里就不行了
代码:
# coding = utf-8
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("hello world hello world")
报错:
Traceback (most recent call last):
File "C:\Users\Administrator\workspace\Test1\src\test2.py", line 8, in <module>
driver.find_element_by_class_name("s_ipt").send_keys("hello world hello world")
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 350, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 662, in find_element
{'using': by, 'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"class name","selector":"s_ipt"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/admini~1/appdata/local/temp/tmpswxeu6/extensions/fxdriver@googlecode.com/components/driver-component.js:9641:26)
at FirefoxDriver.prototype.findElement (file:///c:/users/admini~1/appdata/local/temp/tmpswxeu6/extensions/fxdriver@googlecode.com/components/driver-component.js:9650:3)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/admini~1/appdata/local/temp/tmpswxeu6/extensions/fxdriver@googlecode.com/components/command-processor.js:11635:16)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/admini~1/appdata/local/temp/tmpswxeu6/extensions/fxdriver@googlecode.com/components/command-processor.js:11640:7)
at DelayedCommand.prototype.execute/< (file:///c:/users/admini~1/appdata/local/temp/tmpswxeu6/extensions/fxdriver@googlecode.com/components/command-processor.js:11582:5)
|
|