51Testing软件测试论坛

标题: 求助:python+selenium无法定位 [打印本页]

作者: cc303875235    时间: 2015-1-15 17:04
标题: 求助:python+selenium无法定位
我试过用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)


作者: huohuo668    时间: 2015-1-23 13:50
# 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")
你的这个代码我运行过了没有报错,很正常
作者: ermine    时间: 2015-1-26 19:20
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")

你用的class,和“s_ipt”




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2